Click here to Skip to main content
13,049,684 members (63,993 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I have one application that is using a BinaryFormater to serialize a class, I will call class A, that contains a single property with is a List of T containing another class, I will call class B. I am using a second application to deserialize this class. A Google search found the MSDN and other examples of how to use BinaryFormater.Binder to deserailize an object that was serialized in a differnet assmebly. When I execute my code to deserialize class A in the second assembly, what I am seeing is that the Serialization Binder called is called and returns the Type for the for class A that is in my current assembly that I wish to deserialize to as expected, then the same Binder is called again, this time being passed as arguments the Type Name and Assembly for class B from the orginal Type and Assembly that serialized class B. But my Serialization Binder is only set up for class A, not the class B object that are in it's List property and an exception is thrown. How do you deserialize a Object that contains a List or collection of other Objects in a differnet assembly?
Posted 22-Mar-13 6:39am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

From what I understand in your question you are actually serializing and de-serializing different classes that are looking the same, but CLR is treating them as different since they are declared in independent assemblies.

A common way to solve this is creating a new assembly that contains all the serialized classes and possible the serialization/de-serialization code. Then make both your assemblies reference this new assembly. Now you should be able to use the serialization / de-serialization in both assemblies, because they are referring to the same class, the one in the shared, new assembly.
Member 8681301 25-Mar-13 12:26pm
Thanks for your reply. That is a potential solution and may just very well be what I end up doing. But there is supposed to be a way to make deserializing data in an assembly be assembly independent using Serialization Binder so the serializing assembly class and deserializing assembly class can be in different assemblies. I can not seem to get it to work though.
Steve44 25-Mar-13 12:58pm
Have you tried serialization to/from XML? From what I use these it should be possible to do what you want as long as the structures (property names and their types) are matching.
Member 8681301 3-Apr-13 12:12pm
Serialization to/from XML may be another approach to try since it appears to be assembly independent. I was hoping to use binary serialization for performance reasons and less file storage. Surprisingly though, I found when I serailized the data in my CSV files with the binary serialization the file size increased.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 22 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100