108

I'm doing some work in Visual Studio 2012 Express Edition. I have added an App.config XML file as follows:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
</configuration>

The first thing that happens is a warning comes up that says "The 'configuration' element is not declared". Does anyone know why this is happening? It looks like elements can not be declared inside of until this is resolved.

Thanks!

This is the entire XML:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="Version" value="779" />
<add key="TimeOut" value="60000" />
<add key="LogFileName" value="Log.txt" />
<!-- your Developer Id with eBay -->
<add key="Environment.DevId" value="" />
<!-- your Application Id with eBay -->
<add key="Environment.AppId" value="" />
<!-- your Application Certificate with eBay -->
<add key="Environment.CertId" value="" />
<!-- API Server URL -->
<!-- For production site use: https://api.ebay.com/wsapi -->
<!-- For Sandbox use: https://api.sandbox.ebay.com/wsapi -->
<add key="Environment.ApiServerUrl" value="https://api.sandbox.ebay.com/wsapi" />
<!-- EPS Server URL -->
<!-- For production site use: https://api.ebay.com/ws/api.dll"/-->
<add key="Environment.EpsServerUrl" value="https://api.sandbox.ebay.com/ws/api.dll" />
<!-- eBay Signin URL -->
<!-- For production site use: https://signin.ebay.com/ws/eBayISAPI.dll?SignIn -->
<!-- https://signin.sandbox.ebay.com/ws/eBayISAPI.dll?SignIn -->
<add key="Environment.SignInUrl" value="https://signin.sandbox.ebay.com/ws/eBayISAPI.dll?SignIn" />
<!-- ViewItem URL -->
<!-- For production site use: http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&amp;item={0} -->
<add key="Environment.ViewItemUrl" value="http://cgi.sandbox.ebay.com/ws/eBayISAPI.dll?ViewItem&amp;item={0}" />
<!-- token is for both API server and EPS server -->
<add key="UserAccount.ApiToken" value="" />
<!-- eBay site ID -->
<add key="UserAccount.eBayUserSiteId" value="0" />
<add key="logexception" value="true"/>
<add key="logmessages" value="true"/>
<add key="logsdkmessages" value="true"/>
<add key="logsdk" value="true"/>
<add key="logfile" value="Log.txt"/>
<!-- Rule Name-->
<add key="RuName" value=""/>
<!-- Set this if you access eBay API server behind a proxy server-->
<add key="Proxy.Host" value =""/>
<add key="Proxy.Port" value =""/>
<!-- set proxy server username/password if necessary-->
<add key="Proxy.Username" value=""/>
<add key="Proxy.Password" value=""/>

Eae
  • 4,191
  • 15
  • 55
  • 92
  • 4
    You might have to take a look at what the DotNetConfig.xsd file looks like. can be found in somewhere like C:\Program Files (x86)\Microsoft Visual Studio 10.0\Xml\Schemas – Adriaan Stander Sep 21 '12 at 04:03
  • What is the exact error, what gives this warning? with a full stack frame please? – Simon Mourier May 01 '13 at 08:27
  • It works on my VS2012 Express edition. – Martin Mulder May 01 '13 at 13:47
  • 1
    It is an intellisense issue. With a brand new console application, open the App.config, and the element is underlined in blue with the error "The 'configuration' element is not declared", however, you can still add an section with your settings in it and reference them with the ConfigurationManager class, but when adding the appsettings and – seekerOfKnowledge May 02 '13 at 14:08
  • 2
    wrong answer picked. – JJS Mar 01 '16 at 04:07

9 Answers9

377

Go to XML menu (visual studio top menu item) choose schemas and find for DotNetConfig.xsd and choose Use this schema.

XML - Schemas

Edit XML Schema

Your problem will resolve for sure

Arulkumar
  • 12,966
  • 14
  • 47
  • 68
Ramakrishna
  • 4,928
  • 3
  • 20
  • 24
  • 8
    This should be the answer. Looking at the date this answer was posted (Aug '15), I am not too sure if this answer existed at the time of the question (Sep '12). (Did it?) – Ian Feb 15 '16 at 03:48
  • 1
    This alone did not work for me. Consider this: https://stackoverflow.com/questions/4355278/visual-studio-always-selects-the-wrong-xsd-for-app-config – Matt Jun 14 '17 at 10:37
  • 3
    This answer solved the problem on Visual Studio 2017. Anyway, I don't understand why the DotNetConfig.xsd is not used by default when a .config file is created. – Gael Jul 06 '17 at 07:36
  • [Ramakrishna](https://stackoverflow.com/users/341185/ramakrishna) you da man! Worked perfectly. The application still compiles but the annoying warning message is now gone. – puffgroovy Jul 07 '17 at 13:02
  • This works, more info on this which I noticed in my solution is for .net version 4.5 the DotNetConfig.xsd schema is selected by default but for .net version 4.6 DotNetConfig.xsd needs to be selected as @Ramakrishna suggested in this answer. Thanks! – ZeeProgrammer Aug 17 '17 at 12:50
  • DotNetConfig.xsd is not listed? It's a WPF application. – dvdhns Mar 29 '18 at 22:46
  • This does not work for files that use DotNetConfig471.xsd – Barry Franklin Jul 18 '18 at 14:01
  • This answer solved the problem on VS2013 Update 5 in a ASP.NET MVC 5 project using .NET Framework 4.6.2. – Felipe Romero Dec 05 '18 at 00:01
  • This fixed my Issue. This is the answer. – berkant Nov 24 '19 at 13:31
37
<configuration xmlns="schema URL">
   <!-- configuration settings -->
</configuration>

do changes,like above & try

Ravindra Bagale
  • 17,226
  • 9
  • 43
  • 70
  • 1
    The warning has gone away. Thank you kindly. I must mark this as the answer. – Eae Sep 22 '12 at 04:11
  • 1
    It looks like now the elements inside configuration are not read by the environment which is Visual Studio 2012 Express Edition. – Eae Sep 24 '12 at 05:29
  • @sepoto:if u removes xmlns namespace then it again gives warning – Ravindra Bagale Sep 24 '12 at 06:02
  • 1
    I included the App.config in its entirety in my post. For some reason I have not been able to get it to work properly with the Visual Studio 2012 Express C# Environment. I tried your solution above however I then got warnings for the elements inside of configuration so things became moot. I appreciate your help greatly but I don't believe there is an answer yet. – Eae Sep 25 '12 at 06:32
  • 1
    This answer is partially correct: specifying an xmlns (value can be anything), the **warning** for `configuration` disappears, but an **information message** is issued for `configuration` and for every subelement. If the xmlns points to an actual DTD that defines all the elements, then those messages should disappear as well. – Mike C Sep 18 '15 at 18:09
  • This worked for me to eliminate the warning, but caused failure on startup of the web applications for other users with different VS versions. If you try it make sure everyone can still run the project. – DarrenMB May 13 '20 at 15:51
27

I had the same issue. It is not an error, it is simply a warning; so your application should still compile. I used the following simple config file and the warning is still produced.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime 
             version="v4.0"sku=".NETFramework,
             Version=v4.5"/>
    </startup>
</configuration>

It is an issue that has been raised on the MSDN website, but it does not seem to have been satisfactorily resolved. See link below:

http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvcs/thread/18a1074f-668f-4fe3-a8d9-4440db797439

Stephen Scully
  • 418
  • 4
  • 2
  • 2
    Answer at https://stackoverflow.com/questions/12523996/the-configuration-element-is-not-declared/32116130#32116130 – Ray Cheng Jun 02 '20 at 21:32
6

I had to -> Go to XML menu (visual studio top menu item) choose schemas and select DotNetConfig.xsd AND RazorCustomSchema.xsd AND EntityFrameworkConfig_6_1_0.xsd

user847335
  • 155
  • 2
  • 6
1

I just had this warning popup inside an autogenerated xml file while working on a xaml project.

Using Debug->Clean Solution and Debug->Rebuild Solution fixed it. Might want to try that before getting fancy with the schemas.

ashbygeek
  • 759
  • 3
  • 20
0

Visual Studio 2013 Express Edition is missing the DotNetConfig.xsd (https://connect.microsoft.com/VisualStudio/feedback/details/817322/dotnetconfig-xsd-files-not-present-in-vs-2013-express-for-desktop).

So to get rid of the warning in VS 2013 Express:

The warning should be gone.

appyCrabby
  • 19
  • 2
  • 8
0

Choose use this schema. DotNetConfig.xsd

XLM Menu..... Visual Studio

Works perfectly.

0

I was having less space on my drive which might have resulted in incomplete loading of my application solution. This "the-configuration-element-is-not-declared" problem got solved after i created some space on my drive.

Vallabh
  • 1
  • 1
0

I also got the same warning. After thinking about for some time I realized my error working with SQL (MS SQL).

Warning: the 'configuration' element is not declared

Using C#

App.Config code:

<connectionStrings>
    <add name="dbx" connectionString="Data Source=ServerNameHere;Initial Catalog=DatabaseNameHere;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>

*this calls out the database name in the connectionStrings, when I plugged in my SQL code as a practice I always use the database name, schema, then table. This practice didn't carry over well in Visual Studio as I am a beginner. I removed the db name from my SQL syntax and only called from the schema, data table. This resolved the issue for me.

Form.CS:

 using (SqlCommand cmd = new SqlCommand("SELECT * FROM [DatabaseName].[Schema].[TableName] WHERE [MEPeriod] = '2020-06-01'", con))

Updated to:

using (SqlCommand cmd = new SqlCommand("SELECT * FROM [Schema].[TableName] WHERE [MEPeriod] = '2020-06-01'", con))

This worked for me, I hope this is found as useful.

Martin Brisiak
  • 3,872
  • 12
  • 37
  • 51