-1

I have a Class Library, which is called by a VB6 client and VB.NET client. If the Class Library is called by the VB.NET client then there are settings in the app.config for Log4Net (http://logging.apache.org/log4net/). If the library is called by the VB6 code then there is no logging at the moment.

The question I have is about the app.config. If I have an app.config in the VB.NET client (Windows Forms) and the class library, then I assume that:

If client is Windows Forms then
  Use VB.NET App.config
ElseIf client is VB6 then
  Use Class Library app.config

Is that correct. I have done some research on MSDN, however I cannot find anything explicit and hence the question.

T.S.
  • 18,195
  • 11
  • 58
  • 78
w0051977
  • 15,099
  • 32
  • 152
  • 329
  • possible duplicate of [app.config for a class library](http://stackoverflow.com/questions/5674971/app-config-for-a-class-library) – T.S. Jan 12 '15 at 14:59
  • You can make your class reading setting from different place based on application domain loaded. If it is domain of .net application - use app.config - else use something else. When VB6 is the client, you don't get app domain load app config like .net. I would suggest, investigate differences in appDomain.currentDomain when called by VB6 client vs .net client and report here. I am curious – T.S. Jan 12 '15 at 15:04

3 Answers3

0

I don't think class libraries support app.config files directly - they merely use the app.config / web.config of the assembly that forms the process - so the console app, service, WinForms App etc.

Martin Milan
  • 6,346
  • 2
  • 32
  • 44
0

app.config files are useful only to CLR executable assemblies and they are automatically loaded when the application runs.

If your executable is not a managed application (application developed using VB6 I assume), app.config is useless because CLR won't get loaded into the process (since it is not a managed app).

If your assembly is managed but not executable (class library), it is useless (useless in terms of execution, otherwise it can be used to copy the contents to an executable project's app.config).

Mert Akcakaya
  • 3,109
  • 2
  • 31
  • 42
0

Class library uses the config file of its host, so even if the class library project has a config file, it will not be reference at run time. Instead it will look for the config file of the host executing the DLL.

To avoid recompiling the code after the build to update a variable values like Development DB and Production DB, etc. You can either use setting or hard code a path in your program to look for a 'config' file. I use an XML file, with a key-value pair. I then load and read it to a list, or dictionary that i can use in my application like a 'config' file.

Now when I deploy, I can simply change the 'config' file in the hardcoded location in my dll to whatever environment without the need to rebuild the class library.

meol
  • 1