views:

801

answers:

3

For the last couple months i have ben having some issues with my app.config. I will add an AppSetting key and run my project with no real issue it reads the config file and all is good. Then at a later date i will change the value of that same key and when i run my project I will get the old value of the key. It seems like it isnt saving the file properly or detecting that there was a change in the app.config file. if I clean or rebuild my solution it is fine. Has anyone else seen this issue, is there a hot fix? This is a real problem to have to double check all the time especially when usually the keys are the difference between production and testing environments. Imagine my surprise when i started publishing test messages to my production environment, scary.

Thanks in advance

A: 

Your app.config gets copied to the bin/Debug or bin/Release folder when you compile. If you change your app.config in your source folder, but don't recompile, the change will not get propagated. You need to rebuild to get it moved to the folder where the code is actually executing.

Alternatively, modify the bin/Debug/app.config file instead.

I dont think that that is the case that a re-build is necessary, every time i compile it should check that file and if changes then copy it up. But i cant imagine that everytime i make a change that i would have to do a rebuild for the compiler to recognize my changes. Rebuild vs build rebuild fixes my issue and recompiles all output whereas a build from my understanding checks for any changes to any files and releases only those files

You shouldn't have to clean/rebuild, but simply recompile (F6 rather than Build -> RebuildSolution) to get app.config propagated. But at the very least, your code must be recompiled.

I wonder... is it possible that you have your "Copy To Output Directory" property for the app.config file set to "Do not copy"? To check: right-click on app.config in the Solution Explorer, click Properties.

Randolpho
I dont think that that is the case that a re-build is necessary, every time i compile it should check that file and if changes then copy it up. But i cant imagine that everytime i make a change that i would have to do a rebuild for the compiler to recognize my changes.Rebuild vs buildrebuild fixes my issue and recompiles all outputwhereas a build from my understanding checks for any changes to any files and releases only those files
Brandon Grossutti
app.config is always set to "do not copy" it is an internal build script in vs that send it to output dir as appname.exe.config if i were to copy to output directory it would out put as app.config and would not be referenced or used by the exe
Brandon Grossutti
Good point. I was really just grasping at straws. I've never had the problem you're experiencing. Here's another stab in the dark: your project is multithreaded or multi-process and somehow certain threads/processes are not being shut down and/or restarted when you re-run your project. Because app.config is only read at startup, the old values are therefore still in memory when read by the still-running program.
Randolpho
A: 

Alternativley are you sure that you are editing the right app.config :o

Are you running it in administrator mode?

John Nicholas
A: 

the last sp of vs 2008 seems to have magically solved my issue although i see no note of it

Brandon Grossutti