Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type in assembly is not marked as serializable

I have an entityClass that I wish to serialize as a clone. But this class has a reference assembly from a custom framework which I don't have the access to the code. Whenever I try to serialize entityClass object, it throw the exception,

Type ... in Assembly '..., Version=4.1.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.

like image 602
Little Flying Turtle Avatar asked Jul 09 '15 03:07

Little Flying Turtle


2 Answers

Assuming that the problem is that a field/property on your object is of the problem type, you need to either mark the field/property as NonSerialized or create a derivative of the type which is marked as Serializable

If you derive from the type and mark it as Serialized, you will most likely have to create the serialization logic yourself. This requires you to implement ISerializable and a serialization constructor which takes SerializationInfo and StreamingContext.

This link may help.

like image 101
Phillip Scott Givens Avatar answered Oct 08 '22 10:10

Phillip Scott Givens


If you have PropertyChanged event then set it to [NonSerialized] in all objects(classes) you will Serialize.

    [field: NonSerialized]
    public event PropertyChangedEventHandler PropertyChanged;
like image 23
Bianca Kalman Avatar answered Oct 08 '22 10:10

Bianca Kalman