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.
See if this helps - Reading dll.config (not app.config!) from a plugin module
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With