Geeks in the West Country

Got an invalid XDocument but can’t work out why?

June 15, 2009 · Leave a Comment

This could be the reason…

I uncovered what I suspect may be a .NET Framework bug the other day, when I attempted to validate an XDocument against an XML schema which contained abstract datatypes.  It seems that XDocument.Validate() is unable to resolve derived types properly – it claimed that the concrete type of an XML element was not valid according to its abstract type in the schema.

Only after a lot of checking and self-reassurance that my XDocument really should be valid, and after dragging two colleagues through the problem and having them agree that it should be working too, did I begin to suspect something may be more fundamentally wrong.

I found that Visual Studio’s inbuilt XML document validation did think the document was valid. I then found that if the XDocument were saved out to a string, and validated using another method, there was no validation error.

I explain the problem in depth here. There are some code snippets and a sample Visual Studio project of a simple test case which sandboxes the problem effectively.


Categories: Microsoft
Tagged: , , ,

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

Leave a Comment