使用序列化时出现问题 [英] Problems using serializing

查看:67
本文介绍了使用序列化时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在程序集(.exe)中有一些数据类,应该将其移到另一个程序集(dll).
使用BinaryFormatter对对象进行反序列化.

只要这些类位于原始程序集中,一切都可以正常工作,但是当它们移到DLL时,对旧数据进行反序列化将失败.
我的想法是找不到对象,因为数据文件包含原始程序集的链接.

我实现了一个自定义的序列化绑定程序类,该类将程序集名称更改为新的程序集,并将类型名称中的原始程序集名称替换为新的程序集名称.

序列化仍然失败,可能是因为尽管更改了名称,但仍找不到某些类型.不幸的是,这些对象中有一些通用的字典和列表.

有没有办法在不丢失数据的情况下将旧文件"反序列化为新对象"?

感谢您的帮助!

问候

J.

Hi,

I have some data-classes in an assembly (.exe), that should be moved to another assembly (dll).
The objects are (de)serialized with BinaryFormatter.

As long as the classes are located in the original assembly everything works fine but when they are moved to the DLL deserializing of the old data fails.
My thought was that the objects cannot be found since the data-files contain links to the original assembly.

I implemented a custom serialization-binder-class that changes the assembly-name to the new assembly and replaces the original assembly-name in typename to the new assembly name.

The serialization still fails, probably because some types cannot be found although the names were changed. Unfortunately there are some generic dictionaries and lists inside these objects.

Is there a way to deserialize the "old files" to "new objects" without losing data?

Thanks for help!

regards

J.

推荐答案

您是否尝试过使用 ^ ]强制任何应用程序使用您的新程序集?
Have you tried to use a publisher policy[^] to force any applications to use your new assembly?


嗯……我还没有尝试过.这对于通过例如分发的程序集有效吗MSI?还是仅在我使用此策略的计算机上有效?
Hmmm... I haven''t tried this yet. Does this work for assemblies that are distributed via e.g. MSI? Or does it work only on the machine i use this policy?


这篇关于使用序列化时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆