[英]Unable to XMLSerialize a class generated from xsd.exe which has enum
I have generated classes for an xsd file using xsd.exe which have reference to other xsd file ie link using below command 我已经使用xsd.exe为xsd文件生成了类,这些类引用了其他xsd文件,即使用以下命令进行链接
xsd.exe file1.xsd linkfile.xsd /c
Classes are generated , but in file1.xsd I have a complextype as 生成类,但是在file1.xsd中,我有一个复杂类型
<xsd:complexType name="Department">
<xsd:annotation>
<xsd:documentation>Uses xlink: attributes to connect locations in the document or at any URL by defining an arc and arc type and role.</xsd:documentation>
</xsd:annotation>
<xsd:attributeGroup ref="xlink:deptLink"/>
<xsd:attribute name="SequenceNumber" type="xsd:integer">
<xsd:annotation>
<xsd:documentation>An integer value used to provide an order to multi-instance sibling elements.</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
the xlink:deptLink ie deptLink complextype is in the linkfile.xsd file , so when I genearte classes using the command mentioned above its is creating a field of type enum inside Department class. xlink:deptLink即deptLink复杂类型位于linkfile.xsd文件中,因此当我使用上述命令生成类时,它会在Department类内创建枚举类型的字段。
So when I try to generate xml using 所以当我尝试使用生成XML
XmlSerializer serailizer = new XmlSerializer(typeof(MainClass));
I'm getting error as 我收到错误消息
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Xml.dll System.Xml.dll中发生了类型为'System.InvalidOperationException'的未处理异常
Additional information: There was an error reflecting type 'MainClass'. 附加信息:反映类型'MainClass'的错误。
The actual inner exception is very deep ie in to many layers of inner exception and finally it was 实际的内部异常非常深,即深入到内部异常的许多层,最后
The global XML attribute 'type' from namespace ' http://www.w3.org/1999/xlink ' references distinct types deptLink and orgLink . 命名空间“ http://www.w3.org/1999/xlink ”中的全局XML属性“ type”引用了不同的类型deptLink和orgLink。 Use XML attributes to specify another XML name or namespace for the attribute or types.
使用XML属性为属性或类型指定另一个XML名称或名称空间。
The xlink.xsd which I was using have two -xsd attributes with name "type" 我正在使用的xlink.xsd具有两个名为“ type”的-xsd属性
I have given distinct names and it is working fine 我给了不同的名字,它工作正常
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.