【问题标题】:SGEN: The top XML element from namespace references distinct typesSGEN:命名空间中的顶级 XML 元素引用了不同的类型
【发布时间】:2014-07-23 04:29:18
【问题描述】:

我有以下类(都在同一个命名空间 Test.NamespaceTest 中定义):

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


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

类似

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


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

当 sgen 尝试为这些类创建序列化程序集时,我收到以下错误(B​​aseClass 和 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.

现在,这些类应该使用相同的根名称,所以我定义了 XmlRootAttribute。为了让 sgen 工作,我需要做什么?这些类被序列化并作为 SOAP 请求发送到现有服务,所以如果我添加命名空间值,那么当它尝试反序列化请求时不会弄乱服务吗,因为最初没有定义命名空间?

【问题讨论】:

    标签: c# xml serialization


    【解决方案1】:

    这在添加一些命名空间属性后得到解决。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-06-10
      • 2015-11-11
      • 1970-01-01
      • 2016-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-03
      相关资源
      最近更新 更多