2

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 :)

RichardB
  • 606
  • 2
  • 12
  • 22
  • 1
    See: http://stackoverflow.com/a/2272628/1772300, but I recommend you seriously consider if it might be better to use the app.config with whatever application you're going to use the Dll with (particularly if there are multiple of them). – Cole Cameron Oct 30 '12 at 14:28
  • Thanks Cole, I agree and will put the settings in the callers file. – RichardB Oct 30 '12 at 14:49

1 Answers1

3

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.

Justin Harvey
  • 14,446
  • 2
  • 27
  • 30