Solved

Application Settings are not functioning

Posted on 2008-06-16
7
1,171 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.Net SQL Query 2 Tables Different Databases 3 63
Convert VB web project to C# 3 67
Concurrency Error Persistent using Data Grid View Update C# 2 32
CSS styling problem 3 28
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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 a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

752 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