Search code examples
xmlserializationasp.net-web-apidatacontractserializer

Strange characters appended to node name with XML DataContractSerializer


I'm using ASP.NET Web API to serve out the following class

public class MyListDataContract<T> : List<MyObjectDataContract<T>> where T : MyDataContract

I'm using DataContractAttribute on this specific T and DataMemberAttribute on the instance of this property.

The XML representation of this becomes

<MyObjectDataContractRvPTQ4uA>
...
</MyObjectDataContractRvPTQ4uA>
<MyObjectDataContractRvPTQ4uA>
....
</MyObjectDataContractRvPTQ4uA>
.
.

I have no idea what would be causing this, maybe a naming conflict?


Solution

  • As detailed here the serializer is trying to enforce uniqueness.

    Forcing the DataContractAttribute Name to be MyObjectDataContract{0} works.