Late-bound Object use of Data Member attribute

I’m using late-bound object deserialisation indirectly as part of the Azure MQ implementation. I have a property that is marked with a DataMember attribute so it’s serialised with a different name. When type info is included should this deserialise correctly to an object-typed property?

I’ve put together a Gist to show the “issue” ?

I presume this is the expected behaviour, which I can easily workaround, but just thought I’d check.

You need to annotate the Type as a DataContract as well, e.g:

public class GithubRepository
    [DataMember(Name = "Nom")]
    public string Name { get; set; }
1 Like

Cheers @mythz. Should request DTOs be decorated with [DataContract] if any of the properties have [DataMember]? They work without, but I’ll add them if that could change in the future.

They ideally should so they’re also compatible with other [DataContract] serializers (e.g. .NET’s JSON/XML DataContract Serializers).

1 Like

I’ve just realised when I said it worked, that was when the request was FormData, not JSON! :face_palm: When deserialising FormData, with no [DataContract] attribute on the class, all public properties are deserialised (with or without the [DataMember] attribute).