程序集中的类型未标记为可序列化 [英] Type in assembly is not marked as serializable

查看:1230
本文介绍了程序集中的类型未标记为可序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 entityClass 我想序列化为一个克隆。但是该类具有来自自定义框架的参考程序集,但我无法访问代码。每当我尝试序列化 entityClass 对象时,它都会引发异常

I have an entityClass that I wish to serialize as a clone. But this class has a reference assembly from a custom framework which I don't have the access to the code. Whenever I try to serialize entityClass object, it throw the exception,


Type。 ..在程序集'...,Version = 4.1.0.0,Culture = neutral,PublicKeyToken = null'中未标记为可序列化。

Type ... in Assembly '..., Version=4.1.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.


推荐答案

假设问题是对象上的字段/属性属于问题类型,则需要将字段/属性标记为未序列化,或创建标记为可序列化

Assuming that the problem is that a field/property on your object is of the problem type, you need to either mark the field/property as NonSerialized or create a derivative of the type which is marked as Serializable

如果从类型派生并将其标记为序列化,则很可能必须自己创建序列化逻辑。这要求您实现 ISerializable 和采用SerializationInfo和StreamingContext的序列化构造函数。

If you derive from the type and mark it as Serialized, you will most likely have to create the serialization logic yourself. This requires you to implement ISerializable and a serialization constructor which takes SerializationInfo and StreamingContext.

此链接可能会有所帮助。

这篇关于程序集中的类型未标记为可序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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