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.
June 8, 2007 at 7:47 am
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. :)
October 27, 2011 at 6:34 am
Thanks for teaching me something today.
January 21, 2013 at 9:25 am
This link shows how to specify the location of the Config file, for situations like when the assembly DLL is in the GAC…
http://stackoverflow.com/questions/311253/config-files-for-assemblies-in-gac
April 16, 2009 at 11:53 pm
Thank you! Your note help me!
June 11, 2009 at 8:29 am
Thank you, You are the man!
July 17, 2009 at 7:10 am
Respect! I just won a bet that it couldn’t be done as well.
January 13, 2010 at 7:44 pm
Thank you! You helped too!
June 28, 2011 at 1:40 am
Thank you :) Fantastic …
January 13, 2012 at 3:25 am
want to read value from app.config file of class library. how to do ?