Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Application Settings are not functioning

Posted on 2008-06-16
7
Medium Priority
?
1,178 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
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 

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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
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 …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

670 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