Configuration file (App.Config) for .NET Class Library (.dll)

If you ever deploy a .net class library that isn’t being called by a .net application and references items in the config file then you will have to determine where the .net configuration subsystem will look for the config file and what it should be called. In hindsight, the answer seems rather obvious but I spent several hours figuring this out one day. In my case, I was deploying a managed DLL with a thin COM wrapper that would be called by Excel. In order to get this to work, we placed all the DLLs in the same directory as Excel.exe, called REGASM on the generated .tlb file, and named our config file Excel.exe.config.

Like I said, so obvious in hindsight but not the first (or tenth) thing you think of.

9 Responses to “Configuration file (App.Config) for .NET Class Library (.dll)”

  1. Kinjal Desai Says:

    I wished to achieve something similar.. I wrote a eventSink class to handle OnSave event raised by MS Exchange Server. I wanted to have some variables configurable from outside.. was in similar situation. nothing seemed working properly..

    After placing the config file with the eventSink DLL (not in the folder of Exchange server executable).. ANd wrote following code:

    Configuration oConfig = ConfigurationManager.OpenExeConfiguration(this.GetType().Assembly.Location);

    CustomSectionClass oAppSettings = (CustomSectionClass)oConfig.Sections[“CUSTOM SECTION NAME”];

    Have nice time. :)

  2. Ivan Says:

    Thank you! Your note help me!

  3. Gustavo Says:

    Thank you, You are the man!

  4. Marcelo Says:

    Thank you! You helped too!

  5. selcuk dogan Says:

    Thank you :) Fantastic …

  6. tamil Says:

    want to read value from app.config file of class library. how to do ?


Leave a comment