c# - 将 HybridDictionary 序列化为 byte[]

标签 c# .net serialization

我写了下面的代码

HybridDictionary state = new HybridDictionary();

using (MemoryStream buffer = new MemoryStream())
            {
                BinaryFormatter formatter = new BinaryFormatter();
                formatter.Serialize(buffer , state);


                _backup.Push(buffer .ToArray());

            }

但我在 formatter.serialize(st,state) 上遇到错误,如下所示:

” System.Runtime.Serialization.SerializationException 未被用户代码处理 Message="程序集“System,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089”中的类型“System.ComponentModel.ReflectPropertyDescriptor”未标记为可序列化。"

这是什么意思?

最佳答案

添加

[field:NonSerializedAttribute()]
public event MyEventHandler SomeEvent;

您的事件。这将从序列化中忽略它们。

关于c# - 将 HybridDictionary 序列化为 byte[],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1939449/

相关文章:

c# - 刷新 Windows 窗体应用程序

c# - 试图简化我们的存储库模式

c# - 如何在我的 WinForm 应用程序中调试此 StackOverflowException?

c# - C#HtmlAgilityPack选择主要节点

c# - 使用 Oauth C# 或 VB.net 调用 Yahoo Weather API

c# - 在 View 代码中更改 razor View 的基类

c# - 何时抛出异常以及何时优雅地处理问题

c# - TextWriter 序列化为 UTF-8 字符串

Java序列化和重复对象

hibernate - org.hibernate.type.SerializationException : could not deserialize java. io.EOFException 在 java.io.ObjectInputStream$PeekInputStream.readFully