简体   繁体   English

xxx类型不是预期的。 使用XmlInclude或SoapInclude属性来指定静态未知的类型

[英]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.

相关问题 “不希望使用RoleProxy类型。 使用XmlInclude或SoapInclude属性可以指定静态未知的类型。” NHibernate - “The type RoleProxy was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.” NHibernate 使用 XmlInclude 或 SoapInclude 属性指定静态未知的类型 - Use the XmlInclude or SoapInclude attribute to specify types that are not known statically ASMX 服务错误 - 使用 XmlInclude 或 SoapInclude 属性指定静态未知的类型 - ASMX Service Error - Use the XmlInclude or SoapInclude attribute to specify types that are not known statically Xml序列化异常:不需要类型UserQuery + SpecificContentItem。 使用XmlInclude或SoapInclude - Xml serialization Exception : The type UserQuery+SpecificContentItem was not expected. Use the XmlInclude or SoapInclude 类型xxxx不期望使用xmlinclude或soapinclude - type xxxx not expected use xmlinclude or soapinclude WCF服务引发“未预期类型[…]。 即使已经使用XmlInclude,也要使用XmlInclude […]” - WCF service throws “The type […] was not expected. Use the XmlInclude […]” even if XmlInclude is already being used 调用Web服务时出现问题-使用XmlInclude或SoapInclude属性 - Issue calling a web service - Use the XmlInclude or SoapInclude attribute 如何使用XmlInclude动态指定类型? - How to use XmlInclude to specify types dynamically? XmlInclude属性和派生类 - XmlInclude attribute and derived classes 如何动态添加XmlInclude属性 - How to add XmlInclude attribute dynamically
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM