请帮忙。我在从服务器反序列化数据时出现了错误,
来自命名空间“”的顶级XML元素'Name'引用了不同类型Object1.LocalStrings和System.String。使用XML属性为元素或类型指定另一个XML名称或命名空间。
我的类ObjectType包含属性Name和List<SupportedIp>
。 SupportedIp类也包含属性Name。请参考下面的代码:
[XmlRootAttribute("SupportedIp", Namespace = "http://test.com/2010/test", IsNullable = false)]
public partial class SupportedIp
{[XmlElementAttribute(Namespace = "")]
public string Name
{
get;
set;
} .... }
[GeneratedCodeAttribute("xsd", "2.0.50727.1432")]
[SerializableAttribute()]
[DebuggerStepThroughAttribute()]
[DesignerCategoryAttribute("code")]
[XmlTypeAttribute(Namespace = "http://test.com/2010/test")]
[XmlRootAttribute("ObjectType", Namespace = "http://test.com/2010/test", IsNullable = false)]
public partial class ObjectType
{
/// <remarks/>
[XmlElementAttribute(ElementName = "", Namespace = "")]
public LocalStrings Name
{
get;
set;
}
/// <remarks/>
[XmlArrayAttribute(ElementName = "Supportedip", Namespace = "")]
[XmlArrayItemAttribute(IsNullable = false, Namespace = "")]
public List<Supportedip> Supportedip
{
get;
set;
}
}
当应用程序到达XmlSerializer部分时,会显示错误。我看过一些相关的帖子,但没有明确的答案。