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&item={0} -->
<add key="Environment.ViewItemUrl" value="http://cgi.sandbox.ebay.com/ws/eBayISAPI.dll?ViewItem&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=""/>
Go to XML menu (visual studio top menu item) choose schemas and find for DotNetConfig.xsd and choose Use this schema.
Your problem will resolve for sure
<configuration xmlns="schema URL">
<!-- configuration settings -->
</configuration>
do changes,like above & try
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
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
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.
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:
get a copy of DotNetConfig.xsd from another system or from the web (I used https://gist.github.com/eed3si9n/5dd7dd98ad2b3f668928b23477de35a3)
download to C:\Program Files (x86)\Microsoft Visual Studio 12.0\Xml\Schemas
add the schema following Ramakrishna's answer
The warning should be gone.
Choose use this schema. DotNetConfig.xsd
XLM Menu..... Visual Studio
Works perfectly.
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.
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.
Related
Over here Nuget connection attempt failed "Unable to load the service index for source" I saw many solutions proposed for the
Unable to load the service index for source ...
Error that I find myself getting on an attempted dotnet build right now.
I see suggestions to put XML like either of these
<packageSourceCredentials>
<vstsfeed>
<add key="Username" value="yourname#company.com" />
<add key="Password" value="this is an encrypted password" >
<!-- add key="ClearTextPassword" value="not recommended password" -->
</vstsfeed>
</packageSourceCredentials>
<config>
<!-- Proxy settings -->
<add key="http_proxy" value="host" />
<add key="http_proxy.user" value="username" />
<add key="http_proxy.password" value="encrypted_password" />
</config>
Into Nuget.Config.
How are the passwords encrypted? What should go into the encrypted_password placeholder spaces?
If I install .Net SDK and uses Sample Code, VS says: Cannot resolve symbol 'Configuration' at this line:
var apiContext = Configuration.GetAPIContext();
So, what DLL or namespaces did I missed?
It is a wrapper class around the configuration section.
Please look into \PayPal-NET-SDK-develop\Samples\Source\Utilities\Configuration.cs and create it to suit your configuration.
Don't forget to modify your web.config or app.config
<configSections>
<section name="paypal" type="PayPal.SDKConfigHandler, PayPal" />
</configSections>
<!-- PayPal SDK settings -->
<paypal>
<settings>
<add name="mode" value="sandbox" />
<add name="clientId" value="youclientid" />
<add name="clientSecret" value="yoursecret" />
</settings>
</paypal>
I use app.config to store some info. My file looks like this:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="używajDomyślnie" value="false" />
<add key="sInicjały" value="ŁM" />
<add key="nPrzedstawiciel" value="Łukasz Motyczka" />
<add key="nPozycja" value="Przedstawiciel Naukowo-Handlowy" />
<add key="nTelefon" value="+48 784 567 670" />
<add key="nEmail" value="motyczka.lukasz#bmgrp.pl" />
<add key="dataoferty" value="" />
<add key="ostatniNrOferty" value="" />
</appSettings>
<connectionStrings>
<add name="Oferty_BMGRP.Properties.Settings.BazaDanychConnectionString" connectionString="Data Source=|DataDirectory|\BazaDanych.sdf" providerName="Microsoft.SqlServerCe.Client.3.5" />
</connectionStrings>
<system.windows.forms jitDebugging = "true"/>
</configuration>
The snippet that throws a NullexceptionError is:
if(checkBox1.CheckState == CheckState.Checked)
{
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
AppSettingsSection app = config.AppSettings;
//app.Settings.Clear();
//app.Settings.Add("używajDomyślnie", "true");
//app.Settings.Add("sInicjały", sInicjaly.ToString());
//app.Settings.Add("nPrzedstawiciel", nPrzedstawiciel.ToString());
//app.Settings.Add("nPozycja", nPozycja.ToString());
//app.Settings.Add("nTelefon", nTelefon.ToString());
//app.Settings.Add("nEmail", nEmail.ToString());
config.AppSettings.Settings["używajDomyślnie"].Value = "true"; //<- THIS LINE GIVES ME AN ERROR
config.AppSettings.Settings["sInicjały"].Value = sInicjaly.ToString();
config.AppSettings.Settings["nPrzedstawiciel"].Value = nPrzedstawiciel.ToString();
config.AppSettings.Settings["nPozycja"].Value = nPozycja.ToString();
config.AppSettings.Settings["nTelefon"].Value = nTelefon.ToString();
config.AppSettings.Settings["nEmail"].Value = nEmail.ToString();
config.Save(ConfigurationSaveMode.Modified);
form1.checkBox1.CheckState = CheckState.Checked;
}
When I debug it or build release in VS it works fine. Also it works on my laptop. But on every other machine I have null exception error. Also it worked until I tried to make a setup project (which works but meesed up this one). Whatmore the jit Debugging does not work, I still have a .net error (continue or exit).
Also I did notice that on my computer and some other laptop I was using, when error occurs it shows:
System.NullReferenceException: Odwołanie do obiektu nie zostało ustawione na wystąpienie obiektu.
w Oferty_BMGRP.Form3.button1_Click(Object sender, EventArgs e) w C:\Users\user\Documents\Visual Studio 2010\Projects\BMGRP\Oferty BMGRP\OfertyBMGRP\Form3.cs:wiersz 282
Sorry for polish, but what I want to point is that on both machines it shows path to same folder, which exists only on one of them.
Please help :)
EDIT!
I just found out that if I build the release. Run application and make th above code run, it creates MyApplication.exe.config file, and then app works fine on every computer. How can I make it to work as setup project, where .exe.config is not created, only app.config?
You're trying to set the Value property of a null object. Settings["blah"] is returning null before you even have a chance to set the value.
Try this instead:
config.AppSettings.Add("key", "value");
Or maybe will a null check:
if(config.AppSettings.Settings["key"] == null)
{
config.AppSettings.Add("key", "value");
}
MyApplication.exe.config is app.config, and you shouldn't mess with that paradigm. It's how .net applications are intended to work.
If you want to do your configuration differently than that, than you can either do your own file IO or find another external configuration library.
Everytime when I open my Solution that is using the Enterprise Library from Microsoft I get this error after building or opening my app.config.
After this Message my Visual Studio is shutting down ! My Configuration hasn't changed for a year and I only got this error just since a few days. I don't know where it comes from and why VS is shutting down after this Message ...
Anyone knows this error maybe ?
My Config looks like this :
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="enterpriselibrary.configurationSettings" type="System.Configuration.IgnoreSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=....." />
</configSections>
<enterpriselibrary.configurationSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" applicationName="...." xmlns="http://www.microsoft.com/practices/enterpriselibrary/08-31-2004/configuration">
<configurationSections>
<configurationSection xsi:type="ReadOnlyConfigurationSectionData" name="dataConfiguration" encrypt="true">
<storageProvider xsi:type="XmlFileStorageProviderData" name="XML File Storage Provider" path="......" />
<dataTransformer xsi:type="XmlSerializerTransformerData" name="Xml Serializer Transformer">
<includeTypes />
</dataTransformer>
</configurationSection>
</configurationSections>
<keyAlgorithmStorageProvider xsi:type="FileKeyAlgorithmPairStorageProviderData" name="File Key Algorithm Storage Provider" path="....">
<dpapiSettings xsi:nil="true" />
</keyAlgorithmStorageProvider>
<includeTypes />
</enterpriselibrary.configurationSettings>
Inserting the configsections into the machine.config solved the problem. Unfortunately I don't understand the reason ...
I'm in a ASP.NET project where I need to give several parameters to the administrator that is going to install the website, like:
AllowUserToChangePanelLayout
AllowUserToDeleteCompany
etc...
My question is, will be a good thing to add this into the web.config file, using my own configSession or add as a profile varibles? or should I create a XML file for this?
What do you do and what are the cons and favs?
I originally thought about web.config but I then realized that I should mess up with Website configurations and my own web app configuration and that I should create a different file, them I read this post and now I'm on this place... should I do this or that?
I usually use Settings - available via the project properties - Settings. These can be edited and saved in code, and I write a form / web page to edit them.
If you want to use the XML configuration, there's an attribute called file that reads external files.
You could have a web.config file and a someothername.config file. The someothername.config would have settings like:
<appSettings>
<add key="ConnString" value="my conn string" />
<add key="MaxUsers" value="50" />
</appSettings>
And the web.config would have
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings file="ExternalWeb.config">
<add key="MyKey" value="MyValue" />
</appSettings>
</configuration>
See DevX for the example I stole.
just to let you guys know that I did what configurator recommended but with a twist.
instead of asking all the time (that I need) for
System.Configuration.ConfigurationManager.AppSettings["myKey"];
I just created a static class that would pull this values with what we call by Strongly typed values (so you don't need to remember all the values)
the mySettings class
public static class mySettings
{
public enum SettingsType
{ UserPermitions, WebService, Alerts }
public enum SectionType
{ AllowChangeLayout, AllowUserDelete, MaximumReturnsFromSearch, MaximumOnBatch, SendTo }
public static String GetSettings(SettingsType type, SectionType section)
{
return
ConfigurationManager.AppSettings[
String.Format("{0}_{1}",
Enum.Parse(typeof(SettingsType), type.ToString()).ToString(),
Enum.Parse(typeof(SectionType), section.ToString()).ToString())
];
}
}
the web.config appSettings part
<configuration>
<appSettings file="myApp.config">
<add key="UserPermitions_AllowChangeLayout" value="" />
<add key="UserPermitions_AllowUserDelete" value="" />
<add key="WebService_MaximumReturnsFromSearch" value="" />
<add key="Alerts_SendTo" value="" />
<add key="Alerts_MaximumOnBatch" value="" />
</appSettings>
</configuration>
the entire myApp.config file
<?xml version="1.0" encoding="utf-8" ?>
<!--
###
### This file serves the propose of a quick configuration.
### Administrator can either change this values directly or use the
### Settings tab in the application.
###
-->
<appSettings>
<!-- *** User Access Configuration *** -->
<!-- Allow user to change the panels layout {1: Yes} {0: No} -->
<add key="UserPermitions_AllowChangeLayout" value="1" />
<!-- Allow user to delete a company fro monitoring -->
<add key="UserPermitions_AllowUserDelete" value="1" />
<!-- *** Web Service configuration *** -->
<!-- Maximum responses from the search service -->
<add key="WebService_MaximumReturnsFromSearch" value="10" />
<!-- *** Allerts configuration *** -->
<!-- Send the alerts to the email writeen below -->
<add key="Alerts_SendTo" value="bruno.in.dk#gmail.com" />
<!-- Send an alert when user import more than the number bellow -->
<add key="Alerts_MaximumOnBatch" value="10" />
</appSettings>
So, now I call like this:
p.value = mySettings.GetSettings(
mySettings.SettingsType.WebService,
mySettings.SectionType.MaximumReturnsFromSearch);
Hope that helps someone with the same problem :)
You may also put your configurations in a settings file. In your project, open Properties and go to Settings which looks
like so
To access the values in your code, use Properties.Settings.YourSettingName;
Use Properties.Settings.Default.Reload(); to refresh your settings during runtime