简体   繁体   中英

SGEN: The top XML element from namespace references distinct types

I have the following classes (all defined in the same namespace, Test.NamespaceTest):

[XmlRootAttribute("rootTag")]
public class BaseClass
{
}


[XmlRootAttribute("rootTag")]
public class MyClass : BaseClass
{
}

and similarly

[XmlRootAttribute("rootTag")]
public class Class1
{
}


[XmlRootAttribute("rootTag")]
public class Class2
{
}

When sgen tries to create the serialization assemblies for these classes, I get the following error (same thing for BaseClass and MyClass):

The top XML element 'rootTag' from namespace " references distinct types Test.NamespaceTest.Class1 and Test.NamespaceTest.Class2. Use XML attributes to specify another XML name or namespace for the element or types.

Now, these classes should use the same root name so I defined the XmlRootAttribute. What do I need to do in order to get sgen to work? These classes are serialized and sent to existing services as SOAP requests so if I add namespace values, couldn't that mess up the service when it tries to deserialize the request, since no namespaces are originally defined?

添加一些名称空间属性后,此问题得到解决。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM