BinaryFormatter deserialize gives SerializationException

前端 未结 6 947
别跟我提以往
别跟我提以往 2020-12-16 15:28

I\'m getting an:

System.Runtime.Serialization.SerializationException: Unable to find assembly \'myNameSpace, Version=1.0.0.0, Culture=neutral, Pub

6条回答
  •  醉梦人生
    2020-12-16 15:57

    You will need to provide a reference to the original type somehow so that the utility program knows how to deserialize it.

    The easy way is just to add the DLL the types were originally defined in as a reference to the utility project.

    The code you posted allows you to dynamically load that same DLL when the deserializer determines it can't find the type. This is a more difficult approach (but not that difficult), but in both cases you will need a DLL that defines the types... so probably easiest just to statically link by adding the reference.

    If your types are not currently in a DLL (e.g. if they are in an EXE), I suggest you pull the classes out of the EXE into a new DLL, and reference that DLL both from the original project and from the util project.

提交回复
热议问题