可从不同应用程序访问的序列化文件 [英] Serialized Files Accessible from Different Applications

查看:92
本文介绍了可从不同应用程序访问的序列化文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近做了一些自我测试,就像我以前听到的那样,如果您使用C#序列化对象,然后尝试在其他应用程序中访问序列化的文件,则您将无法读取该文件.

因此,我通过使用人员和联系人两类创建两个系统来进行了尝试. Person包含一个简单的可序列化类,该类具有两个成员:姓名和电话号码,contacts类包含一个person对象列表,而date成员包含该列表的最后更新日期.

这两个系统都包含这些类,但是系统1有一种方法,用于将人员输入列表并进行序列化,并仅检查它是否在工作,就使用了一个按钮,该按钮反序列化文件并遍历列表,从而打印出每个人的的详细信息显示在消息框中.

第二个系统是相同的想法,减去输入法,但是由于不断出现错误,我可以反序列化由系统1生成的文件.

如果有人能提出解决此问题的解决方案,我将不胜感激.此外,如果有人可以解释为什么.NET不允许其他应用程序读取另一个序列化的文件,这对我的理解将是最有用的. >我能够使序列化在程序之间工作的唯一方法是使用SOAPformatter或使用XMLSerializer.

但是,我不知道为什么,我同意这令人沮丧.


I recently did a little test myself, as I had heard before that if you serialize an object in C# then try to access the serialized file in a different application you can''t read that file.

So I tried this by making two systems with the classes person and contacts. Person contained a simple serializable class with two members: name and telephone number and the contacts class contained a list of person objects and a date member containing the last date the list was updated.

Both of the systems contained these classes, however system 1 had a method for inputting the person(s) to the list and serializing and just to check it was working a button that de-serialized the file and looped through the list printing each person''s details out into a message box.

The second system was the same idea, minus the input method, however I could de-serialize the file that was made by system 1 as an error kept appearing.

If anyone could come up with a solution to remedy this problem, I would be most grateful. Furthermore if someone could explain why .NET won''t let another application read another''s serialized file this would be most helpful in my understanding.:thumbsup:

解决方案

The only way I''ve been able to get serialization to work between programs is to either use the SOAPformatter or use the XMLSerializer.

But, I don''t know why and I agree that it''s frustrating.


这篇关于可从不同应用程序访问的序列化文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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