C# Serialization / Deserialization: Same object different project -
basic example:
person person = new person("bob",50); binaryformatter binaryformatter = new binaryformatter(); memorystream memorystream = new memorystream(); binaryformatter.serialize(memorystream, person); byte[] data = memorystream.toarray(); memorystream received = new memorystream(data,false); object obj = binaryformatter.deserialize(received); if (obj person) { person des = obj person; console.writeline("{0} {1}", des.name, des.age); } the problem cannot rebuild byte stream if make same class (names, fields) in different project.
is there solution that?
put shared code in third project, reference shared project in both current projects.
now both have access class, not don't want shared.
is there particular reason you're using .net binary serialization?
the more modern approach use data format json.
specifically json.net.
it's more flexible, allowing deserialize class "looks" same, or use dictionary or dynamic object.
here's answer describing why binary formatter isn't great choice: i hate it, first pointer here "don't that"
Comments
Post a Comment