5
votes

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?

2

2 Answers

12
votes

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.

0
votes

I haven't encountered this particular problem myself but you could try deleting the "obj" folder in your project and rebuilding as suggested in the following post.
Web.config transformation: Unrecognized attribute 'xmlns:xdt'. Note that attribute names are case-sensitive