Solved

Application Settings are not functioning

Posted on 2008-06-16
7
1,163 Views
Last Modified: 2013-12-17
I have an application that has been using User Configuration settings that were defined in the Designer/Settings tab.  The application reads them fine.     I recently added some Application settings by directly editing the app.config XML file, using lines simialr to this:

<add key="EngrNamesPath" value="\\\\Netsys\\usr\\engr\\progData\\engr_with_username_tab.txt" />

Since then, the application doesn't read the new AppSettings.  It still reads the User settings, just not the App settings.  (using System.Configuration; is declared). When the application encounters:

string engrNamesPath = ConfigurationSettings.AppSettings["EngrNamesPath"];

it returns "null"

I am stumped.

0
Comment
Question by:rturney
  • 5
7 Comments
 
LVL 1

Expert Comment

by:CartoonHead
ID: 21794030
Add a reference to System.Configuration and try

string engrNamesPath = ConfigurationManager.AppSettings["EngrNamesPath"];
0
 
LVL 18

Expert Comment

by:jcoehoorn
ID: 21794049
Some observations.  None of these is a solution in itself, but they may help point you to the problem:
1) EngrNamesPath or engerNamesPath?
2) Look for a Settings.settings file in your project (this may be a vb.net only file, but I'm used to seeing it)
3) Make sure you re-build the entire solution.
4) It obviously does see the new setting, or the project would fail to compile at all.
5) Why would you edit the file manually to do this?  Use the IDE.
0
 

Author Comment

by:rturney
ID: 21794174
Thanks for the suggestions.

I already had a reference to System.Configuration, so I replaced

string engrNamesPath = ConfigurationSettings.AppSettings["EngrNamesPath"];  

with

string engrNamesPath = ConfigurationManager.AppSettings["EngrNamesPath"];

It threw exception "does not exist in current context".


Also, I rebuilt the project, but it didn't help.  Still getting a null for the "EngrNamesPath" path.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:rturney
ID: 21794364
What is strange is that it was working when I manually wrote into the app.config XML file.  It was when I decided to replace the manually written XML code (deleted it) and instead use the IDE Settings tab that I started having trouble.  I could go back to the manually edited approach, but would prefer to be consistent and use the IDE Settings.  I even tried deleting the app.config file and starting over, but that didn't work.  The user settings were still recognized, but not the App settings
0
 

Accepted Solution

by:
rturney earned 0 total points
ID: 21795146
I have found a way to fix this problem.

If I declare a reference to "application name".Properties by declaring:

using MyApp.Properties;

Then you can get the values added to the "Settings" tab of the application properties, i.e.,

string engrNamesPath = Settings.Default.EngrNamesPath;



The way I was trying to use:

using System.Configuration;

then

string engrNamesPath = ConfigurationSettings.AppSettings["EngrNamesPath"];  

returns Null for some reason.


0
 

Author Comment

by:rturney
ID: 21795764
The reason I found that solution is because, after reviewing my code, I  saw that I was accessing the User Settings with:
"Settings.Default.<Key name>", i.e.,  string engrNamesPath = Settings.Default.EngrNamesPath;

I had been using that instead of "ConfigurationSettings.AppSettings[Key name]"

I don't know why one way works and the other doesn't.
0
 

Author Comment

by:rturney
ID: 21795793
For those that may be having trouble with this, I also found that when you define a path in the IDE Settings tab, that you should not add extra backslashes like "\\\\Netsys\\user\\engr.  Extra slashes will be added when the property is read.  So the path would be done the normal way:

\\Netsys\user\engr
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now