Search code examples
c#.netdatacontract

Why do serialized DataContracts have bogus URLs in them?


Depending on the size of my class almost half of the serialized text in DataContract classes is filled up with bogus URLs signalling namespaces of serialized classes, like this:

xmlns:i="http://www.w3.org/2001/XMLSchema-instance\
xmlns="http://schemas.datacontract.org/2004/07/Namespace/Of/Serialized/Class"

I get the schema part, and I also understand the advantage of signalling a specific namespace of a class, but the "http://schemas.datacontract.org/2004/07/" part is completely useless as far as I can see. The site does not exist, and even if it were to exist I don't see how it should have any information about my Namespace.

Even if you were to say it's form of keyword to differentiate it from other XML Namespaces, they could have used a shorter one, and one that is not a ULR.

They're making my UnitTest harder to read, and take up lots of space in out Database. Can they be switched off? Can they be changed to non-URLs so my IDE doesn't show them as links? Can they be shortened?


Solution

  • That's because they're URIs, not URLs; their job is to be unambiguous and recognizable; it is not their job to point at anything. To quote from RFC 3986 §1.2.2:

    The URI itself only provides identification; access to the resource is neither guaranteed nor implied by the presence of a URI.

    You can override the generated URI using the Namespace property of DataContractAttribute.