Mitigation: XML Schema Validation
In .NET Framework 4.6, XSD schema validation detects a violation of the unique constraint if a compound key is used and one key is empty.
Impact
The impact of this change should be minimal: based on the schema specification, a schema validation error is expected if xsd:unique
is violated by using a compound key with an empty key.
Mitigation
Whether a schema validation error is detected if a compound key has one empty key is a configurable feature:
Starting with the apps that target .NET Framework 4.6, detection of the schema validation error is enabled by default; however, it is possible to opt out of it, so that the schema validation error will not be detected.
In apps that run under the .NET Framework 4.6 but target the .NET Framework 4.5.2 and earlier versions, a schema validation error is not detected by default; however, it is possible to opt in to it, so that the schema validation error will be detected.
This behavior can be configured by using the AppContext class to define the value of the System.Xml.IgnoreEmptyKeySequences
switch. Because the switch's default value is false
(empty key sequences are not ignored), apps that target the .NET Framework 4.6 can opt out of the behavior by using the following code to set the switch's value to true
:
// Ignore empty key sequences in apps that target .NET 4.6
AppContext.SetSwitch("System.Xml.IgnoreEmptyKeySequences", true);
' Ignore empty key sequences in apps that target .NET 4.6
AppContext.SetSwitch("System.Xml.IgnoreEmptyKeySequences", True)
For apps that target the .NET Framework 4.5.2 and earlier versions, because the switch's default value is true
(empty key sequences are ignored), it is possible to ensure that a compound key with an empty key does generate a schema validation error by using the following code to set the switch's value to false
.
// Do not ignore empty key sequences in apps that target .NET 4.5.1 and earlier
AppContext.SetSwitch("System.Xml.IgnoreEmptyKeySequences", false);
' Do Not ignore empty key sequences in apps that target .NET 4.5.1 And earlier
AppContext.SetSwitch("System.Xml.IgnoreEmptyKeySequences", False)