.net, C#, Microsoft, Technical

.Net CLR Windows Service and the ConfigurationManager class

I created a new windows service and attached a App.Config file to it. Then I went back to the code and tried this:

System.Configuration.ConfigurationManager.GetSection(“Extras”);

For some reason the compiler was not able to figure out the class and kept throwing an error. This does not happen with your standard EXE projects as well as ASP.NET projects. I also did not want to use the
ConfigurationSettings.GetConfig() method as it was obsolete. I fiddled around for a while and eventually ended up manually adding a reference to the
System.Configuration DLL. For those who don’t know, just right click on the References folder in your project, click on Add Reference. Select System.Configuration in the .NET tab and click OK. This should allow you to access the ConfigurationManager class. Back to work now..

I will some day write a post on how to implement custom configuration sections in the App.Config file.

Advertisements

One thought on “.Net CLR Windows Service and the ConfigurationManager class

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s