Silverlight and Windows Phone 7 do not like DTDs
My current Windows Phone 7 project requires the possibility of reading configurations from various servers. For the GIS lovers among my audience: I am trying to read a GetCapabilities document from a WMS server. I was reading this one and this one, and the first one succeeded, while the second one failed. It became even more odd when I tried to write unit tests running from the full framework – then both links processed flawlessly. The error was “NotSupportedException” on XDocument.Load().
The second links contains a DTD from ye goode olde days and it turns out Silverlight and Windows Phone 7 by default are not very fond of DTD’s in documents. After some searching around I found the DtdProcessing Enumeration and I changed this code
var doc = XDocument.Load(stream)
into
using (var reader = XmlReader.Create(stream, new XmlReaderSettings {DtdProcessing = DtdProcessing.Ignore})) { var doc = XDocument.Load(reader) }
And indeed, problem solved