C# xsd.exe在OFX2架构上运行时会生成重复的属性

C# xsd.exe在OFX2架构上运行时会生成重复的属性,c#,xsd.exe,ofx,C#,Xsd.exe,Ofx,使用命令行: "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):

使用命令行:

"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
我从OFX2模式复制了一个类似的XSD模式,然后将其精简到我想要的有用位,生成了一个C#文件,该文件构建得很好,但与完整模式的C#表示具有所有相同的属性


知道为什么吗?OFX模式被破坏了吗?xsd.exe是否已损坏?C#坏了吗?我破产了吗?

好吧,这个答案很长时间都没有了

我刚刚遇到了同样的问题。问题不在foo.cs中,而是在foo.designer.cs中。您必须删除第二个类中的重复属性


C#应该允许跨分部类复制属性,或者修复xsd以忽略除.cs文件之外的所有属性

OFX规范下载的最新版本有一个“OFX3_协议_dotNET.xsd”,它已从“OFX2_协议.xsd”修改为更适合.NET代码生成工具。尽管我还没有反序列化任何XML,但是我从这个xsd生成了C,没有任何问题。

我在不同的模式下遇到了相同的问题(相同的“重复属性”问题)。原因是因为有两个xsd模式(两个生成的文件),在每个模式中我都有相同的元素“类型”,但定义不同。将其中一个类型重命名为不同的名称解决了这个问题

我自己就遇到了这个问题,结果发现对于那些我得到重复属性的类,错误已经在同一名称空间的其他地方声明了。因此,任何试图排除故障的人,都需要确保在给定名称空间下只声明一次罪犯类。例如,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;
            }
        }
    }
}
名称空间示例。导入
{
使用System.Xml.Serialization;
[System.CodeDom.Compiler.GeneratedCodeAttribute(“xsd”,“4.8.3928.0”)]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute(“代码”)]
[System.Xml.Serialization.XmlTypeAttribute(命名空间=”http://www.example.com/Common")]
[System.Xml.Serialization.XmlRootAttribute(“顺序”,命名空间=”http://www.example.com/Order“,IsNullable=false)]
公共部分类OrderType{
私有DocType docField;
公共DocType文件{
得到{
返回此.docField;
}
设置{
this.docField=值;
}
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute(“xsd”,“4.8.3928.0”)]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute(“代码”)]
[System.Xml.Serialization.XmlTypeAttribute(命名空间=”http://www.example.com/Common")]
公共部分类DocType{
private System.Xml.xmlement[]anyField;
/// 
[System.Xml.Serialization.XmlAnyElementAttribute()]
public System.Xml.xmlement[]任何{
得到{
返回这个.anyField;
}
设置{
this.anyField=值;
}
}
}
}

由于XSD.exe将所有导入的类型声明为分部类,并且由于其他早期XSD导入,DocType已存在于同一命名空间中,因此在DocType类上出现重复属性错误。我只是将它的名称空间更改为Example.Imports.Orders,因此此名称空间下只有DocType。我希望这说明了问题和可能的解决方法。

刚刚注意到这个答案-虽然“fix xsd”不太可行,但它肯定是正确的:)这种行为显然是错误的,我不认为这是我们的错。我同意。有些东西坏了,这不是我们的错。谢谢。在VisualStudio中,如果根本不想生成设计器文件,可以编辑xsd文件的属性并将“Custom Tool”设置为空白。