The XML element named 'name' from namespace references distinct types

后端 未结 2 1439
后悔当初
后悔当初 2020-12-20 13:32

Please help. I\'ve got an error while deserializing the data from the server,

The top XML element \'Name\' from namespace \'\' references distinct typ

相关标签:
2条回答
  • 2020-12-20 14:04

    From what you wrote I think that the problem is that you have the same element name (namespace="", name="Name") with two different types of content (string type and localstrings type), which is illegal in xml. This means that every xml parser should raise the fatal error you have printed. The solution is to change either the name of the element or use the same name but associate them with different namespaces. For example instead of:

    [XmlElementAttribute(Namespace = "")]
    

    you could put:

    [XmlElementAttribute(Namespace = "http://test.com/2010/test")]
    

    The core problem seems to be that XMLSerializer uses XSD schema validation. Meaning that each XmlElementAttribute you define has a type attached (read more from here). One of the XSD constraints is "Element Declarations Consistent" constraint meaning that any two elements with the same name (and namespace) have to have the same type (read more from here).

    Hope it helps.

    0 讨论(0)
  • 2020-12-20 14:04

    The argument you declare in the method header must be unique to all web methods in the namespace. As the argument is the top level xml tag of the soap:body. Good luck.

    0 讨论(0)
提交回复
热议问题