Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The answer is given to you in the exception message: </p> <blockquote> <p>Type 'SerializationDemo.Data' in Assembly 'SerializationDemo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is <strong>not marked as serializable.</strong></p> </blockquote> <p>You need to mark your class with the <a href="http://msdn.microsoft.com/en-gb/library/system.serializableattribute.aspx" rel="nofollow"><code>Serializable</code></a> attribute.</p> <pre><code>[Serializable()] class Data : ISerializable </code></pre> <p>From the context it seems like you are going to be transmitting the object down a network (deduced due to the local variable names <em>toSend</em>, <em>toReceive</em>). You need to be aware that, if you where for example, using a client-server model, an object serialized and sent from the server software will not be deserializable from the client software by default.</p> <p>This is because the fundamental characteristic of binary serialization is that it preserves type system fidelity. Type system fidelity denotes that type information is not lost in the serialization process. This means that when you serialize an object, is is not only the "object's state" written to the data stream, but also the name of the class and the containing assembly. Even if you defined the class <code>Data</code> in the assembly that is going to deserialize the data, the deserialize method will fail (throw an exception) because the deserializer will be looking for the type <code>Program1.Namespace.Data</code> not <code>Program2.Namespace.Data</code>. To remedy this you can define your data messages in a mutual assembly (class library) or by defining a <a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.serializationbinder.aspx" rel="nofollow"><code>SerializationBinder</code></a> that will allow you to basically trick the deserialize method into thinking you are still in the same assembly. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload