假设我有以下课程:
[Serializable]
public class foo
{
public bar randomBar;
// required serialization methods would go here
}和
public class bar
{
int barInt;
// constructors and such
}bar是不可序列化的,但foo是可序列化的。当我序列化一个foo对象时,它的randomBar会被序列化,还是会导致错误?
发布于 2014-03-29 15:16:40
序列化程序抛出一个错误。在LinqPad中尝试以下操作:
void Main()
{
var stream = new MemoryStream();
var formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
formatter.Serialize(stream, new Foo { bar = new Bar { barInt = 2 } });
}
// Define other methods and classes here
[Serializable]
public class Foo { public Bar bar; }
public class Bar { public int barInt; }错误是:
Type 'UserQuery+Bar' in Assembly 'query_nsalab, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.https://stackoverflow.com/questions/22732411
复制相似问题