Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

COM wrapped .Net dll config file

I have a .net component library (dll) that I have successfully COM wrapped (using regasm). The .net component requires configuration information.

In the .Net world this is easily solved via the app.config. I can take the specific settings for this dll and add them to a web.config or exe.config so that when the dll is used in a program or on the web, it can access the necessary configuration information.

So my question is, when called via COM (say through an ASP page or even a VBScript), can I and how would I use the configuration file? Ideally, I would rather not hard code certain items.

like image 760
rifferte Avatar asked Feb 01 '26 02:02

rifferte


2 Answers

See if this helps - Reading dll.config (not app.config!) from a plugin module

like image 126
Dipen Bhikadya Avatar answered Feb 03 '26 06:02

Dipen Bhikadya


The problem is that with default COM activation, your managed component runs in the default AppDomain, which inherits its config name from the hosting .exe (eg, if you're running in cscript.exe, it wants to find cscript.exe.config next to cscript.exe, which you don't own). The easiest way to solve this is to create a managed shim that spins up a new AppDomain, then loads the assembly there, specifies the XXX.dll.config file that you want to use in the AppDomainSetup object, then creates and returns the object in the new AppDomain. This basically means you need to create a little managed factory object that ensures .NET is up and running and that your new AppDomain has been created (preferably only once- use the existing domain if creating a second object in the same process), then returns the managed object hosted in the right place. You can make the process completely transparent if you're willing to write an unmanaged shim that fully implements a COM class factory, but that's a little more advanced...

like image 21
nitzmahone Avatar answered Feb 03 '26 06:02

nitzmahone