Unable to find assembly

折月煮酒 提交于 2020-01-24 07:49:24

问题


I'm Serializing an ArrayList to a binary file in order to send it across TCP/IP. The serialized file is created by the server and I hope to be able to deserialize it with the client that I'm writing at the moment.

However, when the client attempts to deserialize it throws a SerializationException because it can't find the assembly (presumably) which serialized the file to begin with.

How do I get around this?


回答1:


Does your arraylist contain custom data type (i.e. your own classes)?

The arraylist won't be deserialized unless the code running the deserialize has access to all of the classes contained within the arraylist.




回答2:


If you are using binary serialization, the client will need to have access to the DLL that contains the type that you are serializing in the ArrayList. I guess I don't really know about your setup to describe how that should be done but that's the gist of it.

If you use something like xml serialization (either using XmlSerializaer or DataContractSerializer), you will be able to produce Xml. You can duplicate the object code on both server/client side if you are truly unable to share the assembly.




回答3:


What is the data that you are trying to send? And how are you serializing it? If you are using BinaryFormatter, then the assembly declaring any custom types must be at both ends.

Note that BinaryFormatter has a range of issues with serialization across systems (including between different versions of the same system). You may want to look at other serializers, such as DataContractSerializer, or protobuf-net (for efficient, cross-platform binary transfer).



来源:https://stackoverflow.com/questions/747149/unable-to-find-assembly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!