2013-05-26 13 views
9

मैं नीचे वर्ग पर निम्न त्रुटि हो रही है सांकेतिक शब्दों में बदलना करने के लिए इस्तेमाल नहीं किया जा सकता। जटिल प्रकार को एन्कोड करने के लिए XmlAttribute/XmlText का उपयोग नहीं किया जा सकता है।XmlAttribute/XmlText जटिल प्रकार

कोई विचार क्यों?

[DataContract] 
[Serializable] 
[XmlRoot("ingredient")] 
public class Ingredient 
{ 
    private string id; 
    private string name; 
    private string description; 

    private IngredientNutrient[] nutrients; 

    public Ingredient(string id, string name, string description, IngredientNutrient[] nutrients) 
    { 
     this.id = id; 
     this.name = name; 
     this.description = description; 
     this.nutrients = nutrients; 
    } 

    public Ingredient(string id, string name, string description) 
    { 
     this.id = id; 
     this.name = name; 
     this.description = description; 
    } 

    public Ingredient() 
    { 

    } 

    [DataMember] 
    [XmlAttribute("id")] 
    public string ID 
    { 
     get { return this.id; } 
     set { this.id = value; } 
    } 

    [DataMember] 
    [XmlAttribute("name")] 
    public string Name 
    { 
     get { return this.name; } 
     set { this.name = value; } 
    } 

    [DataMember] 
    [XmlAttribute("description")] 
    public string Description 
    { 
     get { return this.description; } 
     set { this.description = value; } 
    } 

    [DataMember] 
    [XmlArray("nutrients")] 
    [XmlArrayItem("ingredientnutrient")] 
    public IngredientNutrient[] Nutrients 
    { 
     get { return this.nutrients; } 
     set { this.nutrients = value; } 
    } 

} 

उत्तर

27

आप शायद [XmlElement] बजाय [XmlAttribute] का उपयोग करना होगा। एक विशेषता एक जटिल प्रकार नहीं हो सकता है।

1

एक और सुझाव: रूट तत्व के नीचे उपसर्ग (सूची) गुणों को छोड़ दें।

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