如何解决此序列化异常? [英] How do I get around this Serialization Exception?

查看:104
本文介绍了如何解决此序列化异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个c#程序,该程序读取另一个程序创建的文件,以创建数学问题的统计信息列表.我为两个不同的程序使用了相同的统计信息类.当它尝试读取时,将引发与创建文件的程序有关的序列化异常.

用于保存到文件和从文件读取的stats类不过是要写入文件或从文件读取的公共属性而已.该类中根本没有方法.

我猜想的是,它正在寻找由其他程序创建的文件的程序集.有什么办法可以强制正在读取此文件的程序加载程序集?


谢谢,
Tim

I''m trying to write a c# program that reads a file that was made by a another program to create list of stats for math problems. I used the same stats class for the two different programs. When it tries to read it throws a serialization exception that relates to the program that created the file.

The stats class that is being used to saved to and read from a file is nothing more than just public properties to be written or read from a file. There are no methods in the class at all.

The thing I am surmising is it is looking for an assembly for the file that was made by the other program. Is there a way I can force the program that is reading this file to load the assembly?


Thanks,
Tim

推荐答案

序列化时要记住的两件事:

1)您要序列化的实体必须在应用程序之间可全局访问,即将它们放入GAC.
2)如果使用XmlSerilizer,请确保在实体或类上放置Serializable属性.
3)使用Assembly.LoadLoadFile加载文件,或者使用完全合格的程序集Type.GetType效果很好.
A couple of things to remember when serializing :

1) The entities you are serializing must be globally accessible between applications ie put them in the GAC.
2) If you are using XmlSerilizer be sure to put a Serializable attribute on the entity or class.
3) Use Assembly.Load or LoadFile to load files or if using fully qualified assemblies Type.GetType works well.


这篇关于如何解决此序列化异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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