RichardB
RichardB

Reputation: 606

Using ConfigurationManager.GetSection in a Class Library's App.config

I am writing a class library which has settings in its app.config and which will ultimately be called by a small number of other .NET applications. In order to get settings from it I'm using ConfigurationManager.GetSection such as this:

MyConfiguration process = (MyConfiguration)ConfigurationManager.GetSection("MyGroup/processes");

I've discovered though that the calling application has to have the same app.config inside it's own project in order for this to work, otherwise the class library will throw a NullReferenceException. I'm just wondering if this is normal behavior or if there's any way to ensure that only the class library needs to have app.config available?

Thanks :)

Upvotes: 2

Views: 1581

Answers (1)

Justin Harvey
Justin Harvey

Reputation: 14672

Your class library will always attempt to read from the app.config of the main application that references it. It will not use your class library config file at all.

Upvotes: 3

Related Questions