[英]The type xxx was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically
So the old code base was working fine when I could place a message on MSMQ. 因此,当我可以在MSMQ上放置一条消息时,旧的代码库工作正常。 However the new codebase I received does not work and no idea what I am missing to be honest.
但是,我收到的新代码库无法正常工作,不知道说实话我缺少什么。
Base class: 基类:
[DataContract]
[KnownType(typeof (ReportA))]
[KnownType(typeof (AUpdate))]
[KnownType(typeof (AStatusReport))]
[KnownType(typeof (MsgHeader))]
[KnownType(typeof(BRegistationReport))]
[KnownType(typeof(BAlarmReport))]
[KnownType(typeof(AlarmData))]
[KnownType(typeof(DmpAlarmData))]
public class MyMessage {....}
Then the specific class here, BAlarmReport (derives from MyMessage): 然后是此处的特定类BAlarmReport(源自MyMessage):
[DataContract]
public class BAlarmReport: MyMessage
{ ... }
Then you can have AlarmData as a base which is inherited from DmpAlarmData: 然后,您可以将AlarmData作为继承自DmpAlarmData的基础:
[DataContract]
public class DmpAlarmData : AlarmData
{ .. }
The way I am placing it on MSMQ is the same as before, which was working until I got the new codebase: 我将其放置在MSMQ上的方式与之前相同,直到获得新的代码库之前,该方式一直有效:
var queue = new MessageQueue(@"FormatName:Direct=OS:" + mMSMQQueueNameAndLocation);
var msg = new Message {Body = MyMessage.CreateMessage() };
using (var ts = new TransactionScope(TransactionScopeOption.Required))
{
queue.Send(msg, MessageQueueTransactionType.Automatic); // send the message
ts.Complete(); // complete the transaction
}
am I missing something? 我错过了什么吗?
Fixed. 固定。 sigh
叹
Digging through the inner exceptions led me to the problem where some of the classes did not have a parameterless constructor. 深入研究内部异常会导致我遇到一些类没有无参数构造函数的问题。 But also the subclasses should be declared with the XmlInclude attribute on the base class itself.
但是子类也应该使用基类本身的XmlInclude属性声明。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.