Solved

Application Settings are not functioning

Posted on 2008-06-16
7
1,162 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 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

11 Experts available now in Live!

Get 1:1 Help Now