使用命令行:
"xsd.exe" "OFX 2.1.1 schema/OFX2_Protocol.xsd" /c /namespace:OFX /nologo"
生成的C#源文件无法使用这些错误构建:
D:\blah\OFX2_Protocol.cs(19,6): error CS0579: Duplicate 'System.CodeDom.Compiler.GeneratedCodeAttribute' attribute
D:\blah\OFX2_Protocol.cs(20,6): error CS0579: Duplicate 'System.SerializableAttribute' attribute
D:\blah\OFX2_Protocol.cs(21,6): error CS0579: Duplicate 'System.Diagnostics.DebuggerStepThroughAttribute' attribute
D:\blah\OFX2_Protocol.cs(22,6): error CS0579: Duplicate 'System.ComponentModel.DesignerCategoryAttribute' attribute
D:\blah\OFX2_Protocol.cs(23,6): error CS0579: Duplicate 'System.Xml.Serialization.XmlTypeAttribute' attribute
D:\blah\OFX2_Protocol.cs(24,6): error CS0579: Duplicate 'System.Xml.Serialization.XmlRootAttribute' attribute
一个类似的XSD架构,我从OFX2架构复制然后修剪到我想要的有用位,生成一个C#文件,它构建得很好,但具有与完整架构的C#表示相同的所有属性。
知道为什么吗? OFX架构是否已损坏? xsd.exe坏了吗? C#坏了吗?我坏了吗?
答案 0 :(得分:7)
好的,这个答案很长一段时间......
我刚遇到同样的问题。问题不在于foo.cs,而是在foo.designer.cs中。您必须删除第二个类中的重复属性。
C#应该允许部分类中的重复属性,或者修复xsd以省略除.cs文件之外的所有属性。
答案 1 :(得分:2)
我有不同架构的相同问题(相同的“重复属性”问题)。原因是由于2个xsd模式(2个生成的文件),并且在每个模式中我都有相同的“类型”元素,但具有不同的定义。将其中一种类型重命名为不同的名称解决了问题
答案 2 :(得分:1)
最新版本的OFX规范下载有一个'OFX3_Protocol_dotNET.xsd',它已经从'OFX2_Protocol.xsd'修改为更适合.NET代码生成工具。我已经从这个xsd生成了C#而没有任何问题,尽管我还没有对任何XML进行反序列化。
答案 3 :(得分:0)
我自己遇到了这个问题,事实证明,对于那些我得到重复属性错误的类,已经在同一名称空间下的其他地方声明了。因此,任何尝试进行故障排除的人都希望确保在给定名称空间下仅将罪魁祸首类声明一次。例如,XSD.exe导入生成以下类:
namespace Example.Imports
{
using System.Xml.Serialization;
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.8.3928.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.example.com/Common")]
[System.Xml.Serialization.XmlRootAttribute("order", Namespace="http://www.example.com/Order", IsNullable=false)]
public partial class OrderType {
private DocType docField;
public DocType doc {
get {
return this.docField;
}
set {
this.docField = value;
}
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.8.3928.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.example.com/Common")]
public partial class DocType {
private System.Xml.XmlElement[] anyField;
/// <remarks/>
[System.Xml.Serialization.XmlAnyElementAttribute()]
public System.Xml.XmlElement[] Any {
get {
return this.anyField;
}
set {
this.anyField = value;
}
}
}
}
我在DocType类上遇到重复属性错误,因为XSD.exe将所有导入的类型声明为部分类,并且由于其他早期的XSD导入,DocType已存在于同一命名空间中。我只是将其命名空间更改为Example.Imports.Orders,因此该命名空间下只有DocType。我希望这可以说明问题和可能的解决方法。