亲爱的 Stack Overflow 社区,我以为我永远不必问这个问题,但显然序列化或我对它的使用出了点问题。
我有一个需要序列化的类:
[Serializable]
public class Device : ISerializable, IDisposable
{
public delegate void ListChangedEventHandler(object sender, ListChangedEventArgs e);
public string Name { get; set; }
public string Description { get; set; }
public string IPAddress { get; set; }
[Browsable(false)]
public ThreadSafeBindingList<Item> Items { get; set; }
[Browsable(false)]
public MibEntity AssociatedMibEntity { get; set; }
//methods etc.
}
一点解释:
ThreadSafeBindingList 继承自 System.ComponentModel.BindingList MibEntity 是 SharpSNMP 库的一个类(http://sharpsnmplib.codeplex.com/)
问题: 当我尝试反序列化对象时,MibEntity 始终为空。其他属性都还好。MibEntity 类在外部 dll 中,我在 Device 类所在的项目中引用了它。
这是它的内容:
[Serializable]
public class MibEntity
{
public MibEntity()
{
Children = new List<MibEntity>();
}
[Browsable(false)]
public List<MibEntity> Children { get; set; }
[Browsable(true)]
[Category("General")]
public string OID { get; set; }
private string _name;
[Browsable(true)]
[Category("General")]
public string Name
{
get { return _name; }
set { _name = value; }
}
[Browsable(true)]
public string Description { get; set; }
[Browsable(false)]
public int Value { get; set; }
[Browsable(true)]
public AccessType AccessType { get; set; } //this is enum from SharpSNMP library
[Browsable(true)]
public Status Status { get; set; } //this is enum from same assembly as this class
[Browsable(true)]
public string Syntax { get; set; }
[Browsable(true)]
public bool IsTableEntry { get; set; }
[Browsable(true)]
public IDefinition IDefinition { get; set; } //this is interface from SharpSNMP library
}
我使用 BinaryFormatter 进行序列化和反序列化。感谢您的帮助!