none
SerializationException when deserializing a list containing two objects of different types RRS feed

  • Pregunta

  • I

    I have an error deserializing a list of two diferent object, this is my code:

    [KnownType(typeof(objectA))]
    [DataContract]
    public class objectA 
    {
        [DataMember]
        public string PropertyA { get; set; }
    
        // etc.
    }
    
    [KnownType(typeof(objectb))]
    [DataContract]
    public class objectb 
    {
        [DataMember]
        public string PropertyB { get; set; }
    
        // etc.
    }

    When I deserialize a list of mixed objects the following exception is thrown:

    System.Runtime.Serialization.SerializationException: Type 'objectA' with data contract name 'objectA:htt://schemas.datacontract.org/2004/07/------' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.


    • Editado AlmoraDev miércoles, 6 de febrero de 2013 10:14
    miércoles, 6 de febrero de 2013 9:47