序列化异常.NET信息:System.InvalidOperationException:必须落实System.Collections.Generic.Stack`1默认访问 [英] Serialization exception in .NET: System.InvalidOperationException: You must implement a default accessor on System.Collections.Generic.Stack`1
问题描述
所有我想要做的就是
XmlSerializer serializer = new XmlSerializer(typeof(Stack<int>));
和我得到了以下运行时:
and I get the following at runtime:
System.InvalidOperationException
:您必须实现一个默认的访问
System.Collections.Generic.Stack
`1 [System.Int32中,mscorlib程序,版本= 2.0.0.0,
文化=中性公钥= b77a5c561934e089],因为它自ICollection继承。
System.InvalidOperationException
: You must implement a default accessor on
System.Collections.Generic.Stack
`1 [[System.Int32, mscorlib, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089]] because it inherits from ICollection.
我是不是不应该序列化堆栈&LT; INT&GT;
?
Am I not supposed to serialize the Stack<int>
?
推荐答案
由于Stack类没有一个默认的访问(通过指数为例),你不能用这种方法序列化。
Since the Stack class does not have a default accessor (by index for example) you cannot serialize it with that method.
我会建议你的筹码复制到一个列表,然后在序列名单。
I would suggest copying your stack to a List then serializing the list.
List<int> serializableLIst = new List<int>( myStack );
XmlSerializer serializer = new XmlSeralizer(typeof(List<int>));
请参阅如果不更好地工作。
See if that doesn't work better.
这篇关于序列化异常.NET信息:System.InvalidOperationException:必须落实System.Collections.Generic.Stack`1默认访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!