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

发布于 2024-08-02 00:26:57 字数 995 浏览 3 评论 0原文

使用命令行:

"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# 坏了吗? 我坏了吗?

Using the command line:

"xsd.exe" "OFX 2.1.1 schema/OFX2_Protocol.xsd" /c /namespace:OFX /nologo"

The resulting C# source file fails to build with these errors:

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

A similar XSD schema, which I copied from the OFX2 schema then trimmed down to the useful bits that I wanted, generates a C# file which builds just fine, yet has all the same attributes as the full schema's C# representation.

Any idea why? Is the OFX schema broken? Is xsd.exe broken? Is C# broken? Am I broken?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

少女七分熟 2024-08-09 00:26:57

好吧,这个答案已经很久了......

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

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

Ok, this answer is a long time coming...

I just ran into the same issue. The problem wasn't in foo.cs, but in foo.designer.cs. You have to remove the duplicate attributes in the second class.

C# should either allow duplicate attributes accross partial classes, or fix xsd to omit attributes in all but the .cs file.

沒落の蓅哖 2024-08-09 00:26:57

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

i had the same issue (the same "duplicate attributes" problem) with different schemas. the reason was due to 2 xsd schemas (2 generated files) and in each of them i had the same "type" of element, but with different definitions. renaming of one of the types into different name solved the problem

笑,眼淚并存 2024-08-09 00:26:57

最新版本的 OFX​​ 规范下载包含“OFX3_Protocol_dotNET.xsd”,它已从“OFX2_Protocol.xsd”修改为更适合 .NET 代码生成工具。 我已经从这个 xsd 生成了 C#,没有任何问题,尽管我还没有反序列化任何 XML。

The latest version of the OFX specification download has an 'OFX3_Protocol_dotNET.xsd' which has been modified from the 'OFX2_Protocol.xsd' to be more suited to .NET code generation tools. I have generated C# from this xsd without any problems although I haven't deserialised any XML yet.

Saygoodbye 2024-08-09 00:26:57

我自己就遇到了这个问题,事实证明,对于那些我收到重复属性错误的类,已经在同一名称空间下的其他地方声明了。 因此,任何试图排除故障的人都希望确保罪魁祸首类在给定的命名空间下仅声明一次。 例如,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。 我希望这能说明问题和可能的解决方法。

Just ran into this myself and it turns out that for those classes that I was getting the duplicate attribute error are already declared elsewhere under the same namespace. So, anyone that is trying to troubleshoot, you want to make sure the culprit classes are declared only once under a given namespace. For example, XSD.exe import generated the following class:

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;
            }
        }
    }
}

I was getting duplicate attribute error on DocType class, since XSD.exe declares all imported types as partial classes and DocType was already exist in the same namespace due to other earlier XSD imports. I simply changed the namespace for it to Example.Imports.Orders so there is only DocType under this namespace. I hope this illustrates the problem and possible fixes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文