[英]NetDispatcherFaultException when serializing a class
I have this classes: 我有这个课程:
public class Container
{
public IEventQueue GetEventQueue(){returns a DerivedEventQueue}
}
ComVisible(true), ComDefaultInterface(typeof(IEventQueue ))]
[ClassInterface(ClassInterfaceType.None)]
[Guid("XXX-XXX-XXX-XXX")]
[ProgId("XXXX")]
[DataContract]
[KnownType(typeof(DerivedEventQueue))]
public EventQueue: IEventQueue
{
public MyEvent GetEvent(){...}
}
[DataContract]
[KnownType(typeof(DerivedEventQueue))] //doesnt matter if I have this line or not, I got the same error
//[System.Serializable]
public class DerivedEventQueue: EventQueue, IEventSink
{
...
}
When I called GetEventQueue I got the following exception: 当我调用GetEventQueue时,出现以下异常:
System.ServiceModel.Dispatcher.NetDispatcherFaultException: The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter XXXX:GetEventQueueResult. System.ServiceModel.Dispatcher.NetDispatcherFaultException:格式化程序尝试反序列化消息时引发异常:尝试反序列化参数XXXX:GetEventQueueResult时发生错误。 The InnerException message was 'Element 'XXXX:GetEventQueueResult' contains data of the 'XXX:DerivedEventQueue' data contract.
InnerException消息是“元素'XXXX:GetEventQueueResult'包含'XXX:DerivedEventQueue'数据协定的数据。 The deserializer has no knowledge of any type that maps to this contract.
解串器不知道任何映射到该合同的类型。 Add the type corresponding to 'DerivedEventQueue' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer.'.
将与“ DerivedEventQueue”相对应的类型添加到已知类型的列表中-例如,通过使用KnownTypeAttribute属性或将其添加到传递给DataContractSerializer的已知类型的列表中。 Please see InnerException for more details.
有关更多详细信息,请参见InnerException。 ---> System.Runtime.Serialization.SerializationException: Element 'XXXX:GetEventQueueResult' contains data of the 'XXXX:DerivedEventQueue' data contract.
---> System.Runtime.Serialization.SerializationException:元素'XXXX:GetEventQueueResult'包含'XXXX:DerivedEventQueue'数据协定的数据。 The deserializer has no knowledge of any type that maps to this contract.
解串器不知道任何映射到该合同的类型。 Add the type corresponding to 'DerivedEventQueue' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer.
将与“ DerivedEventQueue”相对应的类型添加到已知类型的列表中-例如,通过使用KnownTypeAttribute属性或将其添加到传递给DataContractSerializer的已知类型的列表中。
DerivedEventQueue is in the KnownType property in the base class, so I don't know why I am getting this exception. DerivedEventQueue在基类的KnownType属性中,因此我不知道为什么会收到此异常。 Can anyone tell me why I am getting this exception?
谁能告诉我为什么我得到这个例外? Thanks!
谢谢!
I'd yry to add known type aytribite on the service level. 我想在服务级别添加已知类型的aytribite。
Also, i think the error is comes from interface you are returning, since wcf does not know how to deserialize it. 另外,我认为错误是由于您返回的接口引起的,因为wcf不知道如何反序列化它。
For.more details about known types, See also http://msdn.microsoft.com/en-us/library/ms730167.aspx 有关已知类型的更多详细信息,另请参见http://msdn.microsoft.com/zh-cn/library/ms730167.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.