Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Application Settings are not functioning

Posted on 2008-06-16
7
Medium Priority
?
1,182 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:Joel Coehoorn
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
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

824 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