I've created a custom System.Configuration.ConfigurationSection
which I'm keeping in a separate config file and including it into my web.config via 'configSource="MyCustomConfigFile.config"'
I've also created a .xsd schema for the custom config file to add some goodies like schema validation / intellisense - which works nicely.
When attempting to start the application (Which is hosted in IIS8, .NET 4.5.1) I'm getting the following error :
Configuration Error Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: Unrecognized attribute 'xmlns'. Note that attribute names are case-sensitive.
Source Error:
Line 1: <?xml version="1.0" encoding="utf-8" ?>
Line 2: <identityServer xmlns="http://myCustomNamespace.xsd">
To be honest, I'm surprised - can anyone tell me how to fix this without removing the xmlns so that I can retain the schema validation/intellisense?
Using the information found here It became clear that the parser is failing to deserialize the config section due to the fact that the config section is not aware of the 'xmlns' attribute - which actually makes PERFECT sense.
In order to fix this you can add the following to your custom configuration section in C# :
public class MyCustomConfigurationSection
{
private const string XmlNamespaceConfigurationPropertyName = "xmlns";
[ConfigurationProperty(XmlNamespaceConfigurationPropertyName, IsRequired = false)]
public string XmlNamespace
{
get
{
return (string)this[XmlNamespaceConfigurationPropertyName];
}
set
{
this[XmlNamespaceConfigurationPropertyName] = value;
}
}
}
This fixes the issue completely.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With