NullReferenceException when validating xml with .NET 4.6
See the question and my original answer on StackOverflowI can reproduce this. Looks like a bug to me (<rant>
.NET 4.6 has a lot...</rant>
). You should report it to Microsoft Connect.
While this is fixed, you can check the source here: http://referencesource.microsoft.com/#System.Xml/System/Xml/Schema/ConstraintStruct.cs,091791a9542f1952
What it tells us is it can be overcome using an AppContext switch, so just add this code before any other and it will work:
AppContext.SetSwitch("Switch.System.Xml.IgnoreEmptyKeySequences", true);
More on this switch is available here: Mitigation: XML Schema Validation - note the sentence: "The impact of this change should be minimal" :-)
PS: I believe you can also change these switches using the proper .config file.