Fix: The Global element 'configuration' has already been declared

C#XsdStylesheetApp Config

C# Problem Overview


I used the second solution of https://stackoverflow.com/questions/179927/how-to-resolve-could-not-find-schema-information-for-the-element-attribute-xxx

I.e. created a XSD with the button to create a scheme. I changed the stylesheet in app.config to app.xsd but now I get the warning:

The Global element 'configuration' has already been declared in app.xsd

Even when changing the name the warning is shown. Does anybody have a solution for this?

C# Solutions


Solution 1 - C#

Rebooting didn't work for me, so I'd like to share what did work.

First, I just upgraded to Windows 8. This problem didn't occur before then. And this issue only happened in one of my app.config files. So I decided to compare the problematic app.config with a good one. In Visual Studio, with the app.config open, I went to Xml -> Schemas. I noticed that the good config only had three of these schemas checked. The bad one had the same three checked, plus a DotNetConfig.xsd. After I changed the Use column to automatic, for DotNetConfig.xsd, the problem went away.

enter image description here

enter image description here

Solution 2 - C#

I had a similar problem to the question you are referring to, I followed these instructions and everything was fine. Make sure the EnterpriseLibrary.Configuration.xsd is in %ProgramFiles%\Microsoft Visual Studio [version]\Xml\Schemas\ first of all, then do this:

> Enterprise Library installs a schema into Visual Studio that provides IntelliSense® for editing Enterprise Library configuration files in the Visual Studio XML editor. You must turn on the schema before you can use it.

> To enable the Enterprise Library configuration schema

> 1. Open the configuration file in Visual Studio by double-clicking it in Solution Explorer.

> 2. On the XML menu, click Schemas... to open the XML Schemas dialog.

> 3. Locate the schema named EnterpriseLibrary.Configuration.xsd. This is installed automatically. However, if it is not shown in the list, click Add and navigate to the folder %Program Files%\Microsoft Visual Studio [version] \Xml\Schemas, then select EnterpriseLibrary.Configuration.xsd and click Open.

> 4. Change the value in the Use column to Use this schema. Then click OK.

Link to the article is here , hopes this helps

Solution 3 - C#

My issue was I went from .Net 4.5 to .Net 4.0. To resolve the issue I switched all the ticked schemas to automatic.

Solution 4 - C#

I struggled with this for a while as well. Turns out, my version of the problem originated from the hidden {PROJECTNAME}.SUO file created by Visual Studio.

My guess is, VS will cache the XSD schema associations in this file. The warnings popped up after I changed the target framework, and they disappeared after I deleted the SUO file and restarted VS.

Solution 5 - C#

With the symptoms as described in the question, and using Visual Studio 2013 (Update 4), I could see in the XML Schemas [sic] dialog that both DotNetConfig.xsd and DotNetConfig40.xsd were selected for use.

I'm using a .NET Framework 4.0 project.

The two XSD files conflict with each other, each defining the same elements, causing the warnings to be emitted.

These schema files are contained in the %programfiles(x86)%\Microsoft Visual Studio 12.0\xml\Schemas\ folder.

DotNetConfig.xsd is in the 1033 sub-folder and appears to be the newer, more complete version.

No matter what settings I selected in XML Schemas, I could not deselect, or remove DotNetConfig40 nor DotNetConfig. I tried "Remove", and changing the Use parameter from "Use this schema" to "Automatic" and then "Do not use this schema".

No matter what was selected, for either file, when I would return to the dialog, both would be selected for use. I also tried the trick of moving to another row before pressing "OK" to no avail.

Finally, I renamed the DotNetConfig40.xsd file to DotNetConfig40 DO NOT USE.xsd to prevent it from being loaded. This immediately solved the problem.

I'm not pleased with having to do that, and worry if it'll have an undesired side effect with other projects. I'll update this post with my results.

Solution 6 - C#

This issue got fixed once I closed the file in the editor that was causing these warnings and recompiled.

Solution 7 - C#

I noticed this issue with my VS2017.

Changing DotNetConfig.xsd to use "Automatic" solved the problem.

enter image description here

Solution 8 - C#

After rebooting the system the problem is solved, meaning I do not get any warnings anymore related to the scheme.

So it seems that rebooting (and possibly some implicit restore/reset removed the warning).

Solution 9 - C#

For me i noticed i had a bunch of XML Schemas that were duplicated, i just simply marked as Don't Use all the ones that weren't related to Visual Studio 2017. The problem immediately disappeared

Solution 10 - C#

Using Visual Studio 2015 Community Edition - generating a web.xsd in the root folder of my project and adding it to the schema list cleared all but one of the warnings,

> The global element 'configuration' has already been declared'.

Closing the web.config file in the text editor and rebuilding the project cleared this warning.

Solution 11 - C#

Necromancing: update 2019 with visual Studio 2017

I tried to do what others suggested:

  • I tried to reboot the system: did not work.
  • open App.Config
  • Menu: XML - Schemas...
  • See that there are several DotNetConfigXX.csd (XX either emoty, or a number)
  • I tried to set them automatic, or to "do not use this schema"
  • I tried to remove duplicate schema's

All this did not work.

However, the solution of OLEG as described here worked.

All I had to do is replace the following part in of all used DotNetConfigXX.xsd files (XX is empty, or a number) with the following code

 <xs:element name="startup" vs:help="configuration/startup" 
 ...
 </xs:element>

Replace with:

<xs:element name="startup" vs:help="configuration/startup">
    <xs:complexType>
        <xs:choice minOccurs="1" maxOccurs="1">
            <xs:element name="requiredRuntime"     vs:help="configuration/startup/requiredRuntime">
                <xs:complexType>
                    <xs:attribute name="version" type="xs:string" use="optional" />
                    <xs:attribute name="safemode" type="xs:boolean" use="optional" />
                </xs:complexType>
            </xs:element>
            <xs:element name="supportedRuntime" minOccurs="1" maxOccurs="unbounded" vs:help="configuration/startup/supportedRuntime">
                <xs:complexType>
                    <xs:attribute name="version" type="xs:string" use="optional" />
                    <xs:attribute name="sku" type="xs:string" use="optional" />
                </xs:complexType>
            </xs:element>
        </xs:choice>
        <xs:attribute name="useLegacyV2RuntimeActivationPolicy" type="xs:boolean" use="optional" />
        <!-- see http://msdn.microsoft.com/en-us/library/bbx34a2h.aspx -->
    </xs:complexType>
</xs:element>

Don't forget to back-up your original .XSD files!

After a restart of visual studio the errors were gone.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMichel KeijzersView Question on Stackoverflow
Solution 1 - C#Bob HornView Answer on Stackoverflow
Solution 2 - C#Tommy GrovnesView Answer on Stackoverflow
Solution 3 - C#Al OptionView Answer on Stackoverflow
Solution 4 - C#IshmaeelView Answer on Stackoverflow
Solution 5 - C#Charles OppermannView Answer on Stackoverflow
Solution 6 - C#RomonovView Answer on Stackoverflow
Solution 7 - C#omostanView Answer on Stackoverflow
Solution 8 - C#Michel KeijzersView Answer on Stackoverflow
Solution 9 - C#TheGeneralView Answer on Stackoverflow
Solution 10 - C#Randall PriceView Answer on Stackoverflow
Solution 11 - C#Harald CoppoolseView Answer on Stackoverflow