DataContractSerializer case-insensitive datamember bug

Posted by Andrew Bullock on Stack Overflow See other posts from Stack Overflow or by Andrew Bullock
Published on 2010-06-07T10:11:21Z Indexed on 2010/06/07 10:32 UTC
Read the original article Hit count: 975

Here is my class:

[DataContract]
public class EventIndex : IExtensibleDataObject
{
    public ExtensionDataObject ExtensionData { get; set; }

    [DataMember]
    private readonly IList<EventDescription> events;
    public IEnumerable<EventDescription> Events { get { return events; } }

    public EventIndex()
    {
        events = new List<EventDescription>();
    }
}

As you can see, events is marked as a member.

When I try and deserialize one of these classes, ReadObject throws a NullReferenceException. After a morning spent inside reflector, it turns out that its trying to deserialize the events collection into the Events getter.

If I rename one of the members (events\ Events) I don't have an issue.

Is there a way to make this work properly, without renaming workarounds or other such nonsense?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about datacontractserializer