如何在c#中修复二进制格式化程序的参数异常

编程入门 行业动态 更新时间:2024-10-23 12:34:20
本文介绍了如何在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#中修复二进制格式化程序的参数异常

本文发布于:2023-11-08 15:53:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1569813.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:异常   参数   程序   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!