views:

89

answers:

1

Hello,

I have the following class which throws an InvalidOperationException when the class is serialized

public class CustomFieldList : CustomField, IList
  {
        public CustomFieldList()
        {
              this.ControlType = Rflex.Framework.MetaData.ControlType.DDL;
        }
        public Type ReferentielType { get; set; }
        public int? CustomCodeTableTypeID { get; set; }
        public CustomCodeTableItem Value { get; set; }
        public override object TheValue { get { return Value; } }
  }

It can't serialize Type which maybe is a normal thing ?

The stack (error translated from French so it's not accurate) :

System.InvalidOperationException: Error while processing XML. ---> System.InvalidOperationException: The type Rflex.WebServices.Objects.Reference.CustomCodeTableItem is not recognized. use XmlInclude or SoapInclude attribute to specify types ..... à Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write32_Type(String n, String ns, Type o, Boolean isNullable, Boolean needType) à Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write33_CustomFieldList(String n, String ns, CustomFieldList o, Boolean isNullable, Boolean needType) à Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write74_JobDescription(String n, String ns, JobDescription o, Boolean isNullable, Boolean needType) à Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write77_Offer(String n, String ns, Offer o, Boolean isNullable, Boolean needType) à Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write96_Offer(Object o) à Microsoft.Xml.Serialization.GeneratedAssembly.OfferSerializer.Serialize(Object objectToSerialize, XmlSerializationWriter writer) à System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)

I tried with attributes but it doesn't want to work.

Thanks in advacnce.

A: 

You'll need this:

[XmlInclude(typeof(Rflex.WebServices.Objects.Reference.CustomCodeTableItem))]

added to the type that is actually returned from your web service.

jvenema