I'm having trouble loading configuration settings in .NET whilst using an assembly over COM interop.
Background: We use lots of VBScript scripts on some servers, that perform various tasks. Commonly, they perform functions such as sending Emails. To facilitate this, I wanted to create a COM object that was creatable from the VBScript, which would help with some of these common featuresets.
Thus, I'm trying to create a .NET assembly that exposes some COM interfaces via interop. I managed to get this working, but then wanted to externalise (rather than hard code) some of the configuration settings.
I'm using this line to retrieve the configuration:
ConfigurationManager.OpenExeConfiguration(this.GetType().Assembly.Location)
This seems to work without issue when I'm testing it from a test project, and referencing it as a .NET project, but if I test it as a COM object, it fails.
The reason for the failure is that in my config file, I have a custom section:
<section name="CustomSection" type="COMObjects.CustomSection, COMObject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e9e8071519bd2f04"/>
However when it tries to load the custom section, it fails to load the assembly "COMObject". To me, this makes sense, as I haven't placed the assembly in the GAC (nor do I want to), so it's struggling to locate it.
Is there a way to help the .NET framework locate the assembly referenced in the config file for a scenario such as this?
Below is the fuslogvw.exe output for the binding:
The operation failed. Bind result: hr = 0x80070002. The system cannot find the file specified. Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll Running under executable C:\Windows\SysWOW64\cscript.exe --- A detailed error log follows. === Pre-bind state information === LOG: User = My-MACHINE\ME LOG: DisplayName = COMObject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e9e8071519bd2f03 (Fully-specified) LOG: Appbase = file:///C:/Windows/SysWOW64/ LOG: Initial PrivatePath = NULL LOG: Dynamic Base = NULL LOG: Cache Base = NULL LOG: AppName = NULL Calling assembly : System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. LOG: This bind starts in default load context. LOG: No application configuration file found. LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v2.0.50727\config\machine.config. LOG: The same bind was seen before, and was failed with hr = 0x80070002. ERR: Unrecoverable error occurred during pre-download check (hr = 0x80070002).
Thanks