如何在c#中修复二进制格式化程序的参数异常 [英] How to fix the argument exception of binary formatter in c#

查看:58
本文介绍了如何在c#中修复二进制格式化程序的参数异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我已经序列化了学生对象并创建了abc.dat文件。

该文件是



[可序列化]

公共班级学生

{

公共字符串名称{get;组; }



public int ID {get;组; }



公共字符串地址{get;组; }





}





现在我已经将ID的数据类型修改为字符串,然后当我尝试使用
来取消secilize abc.dat文件然后我得到了争论异常。



发现错误:

Hi,

I have serialized the student object and have created the abc.dat file.
The file is

[Serializable]
public class Student
{
public string Name { get; set; }

public int ID { get; set; }

public string Address { get; set; }


}


Now i have modified he datatype of ID to string then when i am trying
to de-serailize the abc.dat file then i am getting the arguement exception.

Error found:

A first chance exception of type 'System.ArgumentException' occurred in mscorlib.dll

[Serializable]
    public class Student
    {
        public string Name { get; set; }

        public <b><u></u>string</b> ID { get; set; }

        public string Address { get; set; }


    }

Thanks in advance

推荐答案

你无法将对象序列化为文件,修改原始类,然后期望反序列化过程运行正常。



您应该更仔细地考虑制作类型的ID串。你得到的好处是什么?
You cannot serialize an object to a file, modify the original class, and then expect the deserialization process will run fine.

You should think more carefully about making your ID of type string. What is the benefit you get for that?


只需删除当前的序列化文件(其中包含 int )。继续序列化/反序列化将起作用(除非你再次更改类型:))
Just delete current serialized file (with int in it). Going forward serialization/de-serialization will work (unless you change type again :) )


这篇关于如何在c#中修复二进制格式化程序的参数异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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