[英]Exception when creating XmlSerializer inside an Azure Function V2
[英]How do I troubleshoot this exception when creating an XmlSerializer object?
我在http://www.w3.org/2001/XMLSchema.xsd下載了XML Schema for XML Schema。
然后我使用XSD.EXE從下載的文件中創建一個類。 我調用了類schema.cs
。
然后我執行了這行代碼:
XmlSerializer serializer = new XmlSerializer(typeof(schema));
並得到此錯誤:
名稱空間“http://www.w3.org/2001/XMLSchema”中的XML元素“annotation”已存在於當前作用域中。
如何在不破壞架構的情況下找到重復元素並進行修復?
我認為生成的類有缺陷。
我更改了屬性以修復第一個錯誤,但發現了一個新錯誤。
/// <remarks/>
//[System.Xml.Serialization.XmlElementAttribute("annotation", typeof(annotation))]
[System.Xml.Serialization.XmlElementAttribute("Items", typeof(annotation))]
[System.Xml.Serialization.XmlElementAttribute("import", typeof(import))]
[System.Xml.Serialization.XmlElementAttribute("include", typeof(include))]
[System.Xml.Serialization.XmlElementAttribute("redefine", typeof(redefine))]
public openAttrs[] Items {
get {
return this.itemsField;
}
set {
this.itemsField = value;
}
}
因為注釋元素只是注釋,所以您可以嘗試簡單地過濾所有這些。 首先將XML加載到XDocument
並刪除所有注釋元素。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.