Search Unity

Loading external library with serializable class raises exception

Discussion in 'Editor & General Support' started by Shaikinn, Dec 28, 2020.

  1. Shaikinn

    Shaikinn

    Joined:
    Dec 19, 2020
    Posts:
    1
    Hi! I've been trying to use a library I've made, in unity but whenever I load the dll in the project I get an error saying this

    Error: Could not load signature of Neat_Algorithm.NeatNeuron:.ctor due to: Could not resolve type with token 0100001f (from typeref, class/assembly System.Runtime.Serialization.SerializationInfo, System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a) assembly:System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a type:System.Runtime.Serialization.SerializationInfo member:(null) signature:<none>

    If I remove all the code related to serialization & deserialization it works fine in unity.
    Also the library works fine if I use it outside of unity (both serialization and deserialization)



    Code (CSharp):
    1. using Neat_Algorithm.Neat_Objects.Archives;
    2. using System;
    3. using System.Runtime.Serialization;
    4.  
    5. namespace Neat_Algorithm
    6. {
    7.     [Serializable]
    8.     public class NeatNeuron : ISerializable
    9.     {
    10.         public int ID { get; }
    11.         public string neuronType;
    12.         public float value = 0;
    13.         public double Layer;
    14.         public ActivationFunctions.ActivationFunc ActivationFunction;
    15.         public NeatNeuron(string neurontype, double layer)
    16.         {
    17.             neuronType = neurontype;
    18.             ActivationFunction = ActivationFunctions.tanH;
    19.             Layer = layer;
    20.             ID = Neuron_Archive.AddNeuron(this);
    21.         }
    22.        
    23.         public NeatNeuron(SerializationInfo info, StreamingContext context)
    24.         {
    25.             ID = info.GetInt32("ID");
    26.             neuronType = info.GetString("neuronType");
    27.             ActivationFunction = ActivationFunctions.funcs[info.GetInt32("ActivationFunction")];
    28.             Layer = info.GetDouble("Layer");
    29.             value = (float)info.GetValue("value", typeof(float));
    30.         }
    31.          public void GetObjectData(SerializationInfo info, StreamingContext context)
    32.         {
    33.             info.AddValue("ID", ID);
    34.             info.AddValue("neuronType", neuronType);
    35.             info.AddValue("ActivationFunction", ActivationFunctions.GetFuncIndex(ActivationFunction));
    36.             info.AddValue("Layer", Layer);
    37.             info.AddValue("value", value);
    38.         }
    39.     }
    40. }
    41.  
    Also note that I'm not actually calling any method related to serialization in my code this exception is getting raised when loading the dll
    I usually try to hammer this kind of stuff on my own but I feel completely clueless on this one been trying to figure it out for a long time now, any help would be incredible