Solved

App.Config Recompile

Posted on 2003-12-02
4
1,758 Views
Last Modified: 2012-06-27
App.config in c# projects seems like a useful idea.  The usefulness is greatly dimished though if you have to recompile code for changes in App.Config to be reflected in the running code.  I assumed you wouldn't have to recompile and even found an article explaining that this was the case:

http://www.c-sharpcorner.com/Code/2002/Oct/DynamicProperties.asp

After some investifation though it seems that either I am doing something fundamentally wrong or you really do have to recompile.  I created a quick console application to test this:

using System;

namespace AppConfigTest
{
      class Class1
      {
            [STAThread]
            static void Main(string[] args)
            {
                  Dog objDog = new Dog();

                  while (true)
                  {
                        Console.ReadLine();
                        Console.Write(objDog.Poo());
                  }
            }
      }
}

and a Dog class:

using System;
using System.Configuration;

namespace AppConfigTest
{
      public class Dog
      {
            public Dog()
            {

            }

            public string Woof()
            {
                  return "Woof Woof";
            }

            public string Poo()
            {
                  return "Does a big " + ConfigurationSettings.AppSettings["PooColour"] + " poo";
            }
      }
}

And an App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
      <appSettings>
            <add key="PooColour" value="Yellow" />
      </appSettings>
</configuration>

Now I run the code, press a few keys, make changes to either the original App.config or the one placed in the bin folder but still my dog poo remains yellow.

Can anyone shed any light on this and bring multi coloured abilities to my dog poo?

Thanks

Dave
0
Comment
Question by:daveamour
[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
4 Comments
 
LVL 10

Accepted Solution

by:
smegghead earned 25 total points
ID: 9860633
The contents of the app.config file (or actually yourapp.exe.config) are read in at the point of running your app, not every time you try to access an element from it.

ps. like the class :-)
0
 
LVL 4

Expert Comment

by:wile_e_coyote
ID: 9860642
The App.Config file for a console app is only read once (when the app starts).   Any changes made to the App.Config will not be "seen" by the app until the next time it is launched.

You *could* write code to periodically (re)read the App.Config file (it is just an XML text file, after all), but I get the impression you're looking for something a little more elegant than that.

0
 
LVL 20

Expert Comment

by:TheAvenger
ID: 9862451
The most important thing: if you want to change the settings, change the YourApplicatoin.Exe.config in the OUTPUT folder of your project (normally it's the Debug\Bin or Release\Bin), and not the app.config in the project folder. Then restart the application (not from the environment but directly the EXE file and yuppiii, it's ok
0
 
LVL 19

Author Comment

by:daveamour
ID: 9865023
Ahh ok this makes sense.  It would have been nice if MS included an option for how the App.config is read - once only or in real time.  My problem is that my code is a mission critical windows service which cannot easily be stopped and started.  Not to worry though, I can simply write my own config stuff although MS made ConfigurationSettings sealed :(

I was really just curious about how things worked rather than having a real problem.

Thanks guys

Dave
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

749 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