Search code examples
c#socketsserializationdeserializationbinary-deserialization

C# Serialization - Could not find the assembly


I am working on C# TCP Server-Client programming. My problem is simple but somehow i couldnt figure it out.

I have an object i would like to seriliaze this object send over socket and deserialize client side. But problem is with deserializing. I serialize object with binaryformatter. Actually i am getting the actual byte array i should. But somehow while deserializing i am getting

System.Runtime.Serialization.SerializationException: 'Multi Server, Version=1.0.0.0, Culture=neutural, PublicTokenKey=Null' assembly could not found.

When i try to deserialize on the server side after serializing it has no problem.

I tried to customize binder which didnt work also. I really appriciate if somebody could help me.


Solution

  • If I'm guessing correct, you have 2 projects - "Multi Client" and "Multi Server". You serialize object defined in "Multi Server" and then you have a copy of that class in "Multi Client".

    So you serialize an object "MultiServer.SomeClass" and then you want to make it a "MultiClient.SomeClass". This ain't gonna work.

    You need to create a common dll project (let's name it "MultiCommon", where you will put your class, and reference it by both "MultiServer" and "MultiClient". In this way, you will serialize and deserialize not "MultiServer.SomeClass" but "MultiCommon.SomeClass".