在.NET中反序列化问题 [英] Deserialization problem in .NET

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

问题描述

我创建对象的二进制序列化的文件,这样我可以用它为许多其他项目的数据库文件。它的工作原理相当精细和同一个项目,但是当我尝试反序列化与其他项目的文件,它不会。出现的错误说:XXXX.XXXX组件未找到。那么,应该怎么才能使装配独立的序列化对象???

I created a binary serialized file of my object, so that I could use it as a database file for many other projects. It works quite fine with the same project, but when I try to deserialize that file from other projects, it won't. The error that appears says, "xxxx.xxxx assembly not found". So, how should I serialize the object in order to make it assembly independent???

下面是我的code:

            // Binary formatter
            IFormatter formatter = new BinaryFormatter();
            Stream stream = new FileStream("BinarySerialization.bin",
                                     FileMode.Create,
                                     FileAccess.Write, FileShare.None);
            formatter.Serialize(stream, words);
            stream.Close();

我需要做什么修改???请为我提供一个工作code例子/样本。

What amendments do I need to do??? Please provide me with a working code example/sample.

感谢。

推荐答案

我把我所有的模型都必须序列化到一个单独的组件。 然后你引用这个组件无处不在,你需要反序列化的模型。

I would put all my models that have to be serialized into a seperate assembly. Then you reference this assembly everywhere you need to deserialize the Models.

如果不是你需要某种形式的发电机,是重新创建模型基于一些模式(等同于WCF确实有它的实用工具)或者使用普​​通的格式是XML,以保存数据。

If not you need some kind of generator, that recreates the models based on some schema (same as WCF does with its utilities) or use plain formats like XML to persist your data.

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

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