简体   繁体   English

SGEN:命名空间中的顶级XML元素引用了不同的类型

[英]SGEN: The top XML element from namespace references distinct types

I have the following classes (all defined in the same namespace, Test.NamespaceTest): 我有以下类(所有类都在同一命名空间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): 当sgen尝试为这些类创建序列化程序集时,出现以下错误(对BaseClass和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. 现在,这些类应使用相同的根名称,因此我定义了XmlRootAttribute。 What do I need to do in order to get sgen to work? 为了使sgen正常工作,我需要做什么? 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? 这些类被序列化并作为SOAP请求发送到现有服务,因此,如果我添加名称空间值,由于最初未定义任何名称空间,当尝试反序列化请求时,服务是否会造成混乱?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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