I am trying to set the compatibility switch "Switch.System.Xml.IgnoreEmptyKeySequences" from an entry in an app.config (or web.config) file, but the override appears to be ignored. To remove the possibility of any strange configuration my existing project I have created a brand new .Net 4.6 Web Forms project (and associated test project) in VS2015.
I am following the microsoft guidance for AppContext switches https://msdn.microsoft.com/en-us/library/mt298997(v=vs.110).aspx and https://msdn.microsoft.com/en-us/library/mt270286(v=vs.110).aspx
The app.config file is as follows:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<AppContextSwitchOverrides value="Switch.System.Xml.IgnoreEmptyKeySequences=true"/>
</runtime>
</configuration>
The code I am using to read the value is:
bool valueWasFound;
bool valueFromContext;
string switchString = "Switch.System.Xml.IgnoreEmptyKeySequences";
valueWasFound = AppContext.TryGetSwitch(switchString, out valueFromContext);
And yet I consistently get false
for both valueWasFound
and valueFromContext
.
I have tried this with other switch values with the same result.
I find that if I set the switch in code using
AppContext.SetSwitch("Switch.System.Xml.IgnoreEmptyKeySequences", true);
Then the switch is set as anticipated (i.e. I get true
for both valueWasFound
and valueFromContext
).
But I would very much prefer to set this in the App.Config / web.config
TryGetSwitch
yields the same result as you have, setting it in code appears to work. – Nihi