发送从ObservableCollection继承的Collection时出错. [英] Error sending Collection inherited from ObservableCollection<>
问题描述
大家好
我想使用WCF将这样的类发送给客户端
[DataContract]
[KnownType("GetKnownType")]
公共类MyCollection< T> :ObservableCollection< T>其中T:myEntity,new()
{
[DataMember]
private List< T>删除;
其他东西.....
私有静态Type [] GetKnownType()
{
Type [] t = new Type [1];
t [0] = typeof(ObservableCollection) ;
}
}
但是当服务器尝试发送集合时,会引发此异常
运行时遇到致命错误.错误的地址在线程0xa5c上的0x50204fd8处.错误代码为0x80131623.此错误可能是CLR或用户代码中不安全或不可验证的部分中的错误.该错误的常见来源包括COM-interop或PInvoke的用户封送处理错误,这些错误可能会破坏堆栈.
如果我像这样更改班级:
[DataContract]
公共类MyList< T> :INotifyPropertyChanged其中T:myEntity,new()
{
[DataMember]
私有ObservableCollection< T>项目;
[DataMember]
私有列表< T>删除;
然后,我可以毫无问题地发送收藏集.
我想念什么?
谢谢
此博客为该主题带来了很多亮点
http://kentb.blogspot.com/2007/11/serializing-observablecollection.html
Hi all
I want to send a class like this to a client, using WCF
[DataContract]
[KnownType("GetKnownType")]
public class MyCollection<T> :ObservableCollection<T> where T : myEntity, new()
{
[DataMember]
private List<T> deleted;
other stuff .....
private static Type[] GetKnownType()
{
Type[] t = new Type[1];
t[0] = typeof(ObservableCollection<T>);
return t;
}
}
but when the server try to send the collection raise this exception
The runtime has encountered a fatal error. The address of the error was at 0x50204fd8, on thread 0xa5c. The error code is 0x80131623. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.
If i change the class like this:
[DataContract]
public class MyList<T> :INotifyPropertyChanged where T :myEntity , new()
{
[DataMember]
private ObservableCollection<T> items;
[DataMember]
private List<T> deleted;
then, i can send the Collection without problems.
What i am missing?
Thanks
This blog throws good amount of light on this topic
http://kentb.blogspot.com/2007/11/serializing-observablecollection.html
这篇关于发送从ObservableCollection继承的Collection时出错.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!