Ask a questionAsk a question
 

AnswerIList - SerializationException

  • Thursday, March 16, 2006 11:18 PMianic Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I'm geting serialization exception while trying to send IList childs collection.
    This is my class:
    [DataContract(Name = "Parent", Namespace = "MyNamespace")]
    public class Parent: ModelBase
    {
    ...
            [DataMember(Name = "Childs", Order = 6)]
            protected IList _childs = null;

    ...

    This is exception:
    System.Runtime.Serialization.SerializationException: No type has DataContract 'http://schemas.microsoft.com/2003/10/Serialization/Arrays:ArrayOfanyType' in element 'MyNamespace:Childs'. Use KnownType attribute to specify types that are not known statically at System.Runtime.Serialization.XmlFormatterDeserializeContext.InternalDeserialize(XmlReaderDelegator xmlReader, DataContract& dataContract, Dictionary`2 knownDataContracts)

    Is there a way to send this collection, or to instruct XmlFormater to deserialize it as ArryList?

Answers

  • Friday, March 17, 2006 2:56 AMSowmy Srinivasan Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Can you please post which CTP bits you were using? With Feb CTP this should work. you must be able deserialize it as an array.

    Please consider adding object[] to Known types for your case.

    [DataContract(Name = "Parent", Namespace = "MyNamespace")]

    [KnownType(typeof(object[]))]
    public class Parent: ModelBase
    {
    ...
            [DataMember(Name = "Childs", Order = 6)]
            protected IList _childs = null;

    To deserialize this as an ArrayList you need to change the member type to ArrayList

    I hope this answers your question.

     

All Replies

  • Friday, March 17, 2006 2:56 AMSowmy Srinivasan Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Can you please post which CTP bits you were using? With Feb CTP this should work. you must be able deserialize it as an array.

    Please consider adding object[] to Known types for your case.

    [DataContract(Name = "Parent", Namespace = "MyNamespace")]

    [KnownType(typeof(object[]))]
    public class Parent: ModelBase
    {
    ...
            [DataMember(Name = "Childs", Order = 6)]
            protected IList _childs = null;

    To deserialize this as an ArrayList you need to change the member type to ArrayList

    I hope this answers your question.

     

  • Friday, March 17, 2006 2:06 PMianic Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Thanks Sowmy,
    it is working now with feb CTP I used go live version before.