5

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 Answers 2

12

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Also you should add properties for "xmlns:xsi" and "xsi:schemaLocation" if you want to specify location of your xsd schema.
Can you elaborate on that please?
Is this the only way that you've found to remedy this issue? I mean this works fine, but seems like there should be an easier way!
That's the only way that I'm aware of
This well-written answer seems to be based in using the proper asp.net mechanisms to extend web.config in a robust way. Just my opinion - and I am trying to work this out on a legacy project I am reviving - which has a 3rd-party package that is utilizing configuration aspects of web.config.
0

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

1 Comment

@Peter Evans - I see that you want to be helpful, and that is the right idea. If you are making suggestions that might help the person, and are not well-defined steps to the actual solution - you might want to post them as comments to the original question - where the person with the problem and confirm/deny that your suggestion is helpful. Posting these comments to the question help clarify the situation, and will not likely earn you down votes. Hope this is helpful to you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.