2

For a specific reason, i need to create a WPF-DLL which uses a WCF service to get some data and then displays it when an application calls this WPF assembly. The WPF assembly, in turn, requires binding information which is written in an app.config. Is there a way to force the DLL to read the binding information in a seperate app.config?

Thanks in advance for the hint.

Best regards,

Benjamin Martin
  • 576
  • 1
  • 8
  • 27
  • 3
    http://stackoverflow.com/questions/3255820/apply-an-app-config-to-my-dll-assembly – Ahmed ilyas Apr 30 '15 at 13:19
  • I'm a little confused, you want to read the settings out of the app.config from the .exe, or do you want to use the settings out of the app.config from the dll? – Ron Beyer Apr 30 '15 at 13:24
  • 1
    I want the DLL to automatically read it's own app.config when it is called by the host app. – Benjamin Martin Apr 30 '15 at 13:30
  • @Ahmed: Yeah it could be a solution, but it requires that the keys in the host's app.config and the keys in the separate file need to be different right? – Benjamin Martin Apr 30 '15 at 13:32
  • 4
    It's quite simple. DLLs just do not have their own config files. All of configuration starts from the exe's app.config or from web.config. This mistaken impression is exacerbated by the fact the some of the VS tooling will automatically add an app.config to DLLs. But at best, those should be thought of as showing you what config the DLL depends on or being something you can copy & paste into the correct config file. – Damien_The_Unbeliever Apr 30 '15 at 13:34
  • 2
    In case it shouldn't be configurable at all, the WCF setup might be done in the library's code. – Clemens Apr 30 '15 at 13:39

2 Answers2

1

As a class library dll isn't executing, it won't use an app config. The idea being that multiple applications could use your library and pass slightly different values in, making your library dynamic and reusable.

If you need to pack in static values for some reason that aren't configured. You could consider a resource or settings file, or even a simple xml document called mylibrary.config.xml or whatever and manually parse it.

Mark McGookin
  • 932
  • 1
  • 16
  • 39
0

Go to App properties -> Settings tab; add your settings there.

Use Properties.Settings.Default.<SettingName> to access the setting. That's it!

It works for me.

Parthiban
  • 41
  • 2