2010-02-03 8 views
6

बनाता है मैं एक्सएसडी फ़ाइलों के संग्रह से सी # कक्षाएं उत्पन्न करने के लिए .NET XSD.EXE आयातक का उपयोग कर रहा हूं। जब मैंने कक्षाओं में से किसी एक को एक्सएमएल में क्रमबद्ध करने की कोशिश की तो यह असफल रहा (अमान्यऑपरेशन अपवाद), और जब मैंने इसमें खोद दिया तो मुझे पता चला कि निर्मित वर्गों में से एक गलत है।.NET xsd आयातक unserializable वर्ग

<xsd:complexType name="SuccessType"> 
    <xsd:annotation> 
     <xsd:documentation>Indicates in a response message that a request was successfully processed.</xsd:documentation> 
    </xsd:annotation> 
    <xsd:sequence> 
     <xsd:element ref="Warnings" minOccurs="0" maxOccurs="unbounded"/> 
    </xsd:sequence> 
</xsd:complexType> 
<!-- .. snip .. --> 
<xsd:element name="Warnings" type="WarningsType"> 
    <xsd:annotation> 
     <xsd:documentation>The processing status of a business message and any related warnings or informational messages.</xsd:documentation> 
    </xsd:annotation> 
</xsd:element> 
<!-- .. snip .. --> 
<xsd:complexType name="WarningsType"> 
    <xsd:annotation> 
     <xsd:documentation>A collection of warnings generated by the successful processing of a business message.</xsd:documentation> 
    </xsd:annotation> 
    <xsd:sequence> 
     <xsd:element ref="Warning" maxOccurs="unbounded"/> 
    </xsd:sequence> 
</xsd:complexType> 
<!-- .. snip .. --> 
<xsd:element name="Warning" type="WarningType"> 
    <xsd:annotation> 
     <xsd:documentation>Defines details of a warning that occurred during message processing.</xsd:documentation> 
    </xsd:annotation> 
</xsd:element> 
<!-- .. snip .. --> 
<xsd:complexType name="WarningType"> 
    <xsd:annotation> 
     <xsd:documentation>Defines details of a warning that occurred during message processing.</xsd:documentation> 
    </xsd:annotation> 
    <xsd:sequence> 
     <xsd:element ref="WarningCategory"/> 
     <xsd:element ref="WarningCode"/> 
     <xsd:element ref="WarningShortMessage"/> 
     <xsd:element ref="WarningMessage"/> 
    </xsd:sequence> 
</xsd:complexType> 

और यहाँ सी # यह से उत्पन्न कोड है::

public partial class SuccessType 
{ 

    private WarningType[][] warningsField; 

    /// <remarks/> 
    [System.Xml.Serialization.XmlArrayItemAttribute("Warning", typeof(WarningType), IsNullable = false)] 
    public WarningType[][] Warnings 
    { 
     get 
     { 
      return this.warningsField; 
     } 
     set 
     { 
      this.warningsField = value; 
     } 
    } 
} 

यह WarningsWarningType की एक सरणी की एक सरणी बनाया

यहाँ उचित XSD कोड है।

  • एक अस्थायी वर्ग (परिणाम = 1) जनरेट करने में असमर्थ: जब मैं कि क्रमानुसार करने एक्सएमएल करने का प्रयास मैं एक InvalidOperationException अपवाद मिलता है।
  • त्रुटि CS0030: प्रकार कनवर्ट नहीं कर सकता 'WarningType []' 'WarningType' के लिए
  • त्रुटि CS0030: प्रकार कनवर्ट नहीं कर सकता 'WarningType []' 'WarningType'
  • त्रुटि CS0029 करने के लिए: परोक्ष करने के लिए प्रकार 'WarningType' कनवर्ट नहीं कर सकता 'WarningType []'
  • त्रुटि CS0029: परोक्ष करने के लिए प्रकार 'WarningType' कनवर्ट नहीं कर सकता 'WarningType []'

लेकिन अगर मैं WarningType[][]WarningType[] करने से उत्पन्न कोड बदलने तो यह ठीक serializes।

जब भी मैं इसे पुन: उत्पन्न करता हूं (जो उम्मीद है कि अक्सर आगे जा रहा है) उत्पन्न होता है, तो क्या कोई अन्य समाधान है? क्या यह xsd.exe में एक बग है या एक्सएसडी फ़ाइल गलत है? शायद XmlSerializer में कोई समस्या है?

मुझे क्या चाहिए सी # कोड है जो XSD के विरुद्ध मान्य XML पर सही ढंग से क्रमबद्ध करता है। अभी जंजीर सरणी गलत लगती है क्योंकि अगर मैं इसे हटा देता हूं तो यह एक्सएमएल उत्पन्न करता है।

मैं दृश्य स्टूडियो का उपयोग कर रहा 2008

+0

मुझे विश्वास है कि यह एक ज्ञात बग है जिसे ठीक नहीं किया जाएगा। Https://connect.microsoft.com/VisualStudio/feedback/details/362727/xsd-exe-incorrect-class-generated-for-abstract-type-with-derived- अन्य एक्सएसडी बग के लिए टाइप करें जो वे कहते हैं, नहीं देखेंगे तय की। –

+0

@ जॉन सॉंडर्स - बगजर, यही मुझे लगा। क्या XSD.exe का कोई अच्छा विकल्प है जिसे आप जानते हैं? –

+0

समस्या अभी भी .NET 4.5.1 – yW0K5o

उत्तर

4

xsd.exe उपकरण में कीड़े हैं। मुझे यह विशेष याद नहीं है, लेकिन मुझे जंजीर सरणी के साथ समस्याएं मिल रही हैं, और यह संभव है कि यह एक बग बनी रहे। यदि आप इच्छुक हैं, तो आप माइक्रोसॉफ्ट से भी XsdObjbectGen टूल का उपयोग कर सकते हैं, लेकिन .NET SDK से स्वतंत्र रूप से और आउट-ऑफ-बैंड जारी किए गए हैं।

एक चीज जो आप कर सकते हैं वह विपरीत दिशा में जाती है: सी # कोड लिखें, फिर xsd.exe के साथ स्कीमा उत्पन्न करें, और देखें कि अलग क्या है। यह संभव है xsd.exe चाहता है कि स्कीमा एक विशेष तरीके से दिखने के लिए, सही ढंग से जंजीर सरणी के लिए सही कोड उत्पन्न करने के लिए।


दरअसल, अपने प्रश्न को फिर से पढ़ने पर, आपने कभी नहीं कहा कि आप वास्तव में क्या चाहते थे। क्या आप सफलता टाइप को सरणी के सरणी रखना चाहते हैं, या नहीं?

और यह WarningsType या WarningType है? आपके द्वारा प्रदत्त कोड स्निप के बीच कुछ असहमति है।

public class WarningType 
{ 
    public String oof; 
} 


public partial class SuccessType 
{ 
    private WarningType[][] warningsField; 

    /// <remarks/> 
    [System.Xml.Serialization.XmlArrayItemAttribute("Warning", typeof(WarningType[]), IsNullable = false)] 
    public WarningType[][] Warnings 
    { 
     get 
     { 
      return this.warningsField; 
     } 
     set 
     { 
      this.warningsField = value; 
     } 
    } 
} 

... तो एक DLL में संकलित:


मान लिया जाये कि आप सरणी के-सरणियों चाहता था, मैं इस सी # कोड लिखा था। तब मैं xsd.exe कि DLL पर चलता था, और इस XSD उत्पन्न:

<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <xs:element name="WarningType" nillable="true" type="WarningType" /> 
    <xs:complexType name="WarningType"> 
    <xs:sequence> 
     <xs:element minOccurs="0" maxOccurs="1" name="oof" type="xs:string" /> 
    </xs:sequence> 
    </xs:complexType> 
    <xs:element name="SuccessType" nillable="true" type="SuccessType" /> 
    <xs:complexType name="SuccessType"> 
    <xs:sequence> 
     <xs:element minOccurs="0" maxOccurs="1" name="Warnings" type="ArrayOfArrayOfWarningType" /> 
    </xs:sequence> 
    </xs:complexType> 
    <xs:complexType name="ArrayOfArrayOfWarningType"> 
    <xs:sequence> 
     <xs:element minOccurs="0" maxOccurs="unbounded" name="Warning" type="ArrayOfWarningType" /> 
    </xs:sequence> 
    </xs:complexType> 
    <xs:complexType name="ArrayOfWarningType"> 
    <xs:sequence> 
     <xs:element minOccurs="0" maxOccurs="unbounded" name="WarningType" nillable="true" type="WarningType" /> 
    </xs:sequence> 
    </xs:complexType> 
</xs:schema> 

... और यह राउंड ट्रिप। यदि मैं उस स्कीमा पर xsd.exe चलाता हूं, तो मुझे एक प्रकार मिलता है जो सरणी के सरणी को लपेटता है।

+0

में मौजूद है, मैंने अपना प्रश्न अधिक स्पष्ट होने के लिए अपडेट किया है। क्या आपको पता है कि मैं XSDObjectGen कहां पा सकता हूं? –

+0

xsdobjectgen: http://www.microsoft.com/downloads/details.aspx?familyid=89e6b1e5-f66c-4a4d-933b-46222bb01eb0&displaylang=en – Cheeso

+0

क्या कोई संस्करण है जो .NET 1.1 के अलावा कुछ भी काम करता है? मैं इसे भी इंस्टॉल नहीं कर सकता। मैं इसे एक बग पर चॉक करने जा रहा हूं: https://connect.microsoft.com/VisualStudio/feedback/details/362727/xsd-exe-incorrect-class-generated-for-abstract-type-with-derived-types –

संबंधित मुद्दे