Jan
Jan

Reputation: 2490

Correctly locate DLL's App.config section handler assemblies

I am writing a DLL which is loaded by a third party application (The FitNesse framework's test runner, the DLL is a test fixture).

The DLL has its own App.config file (say MyDll.dll.config), and I can tell FitNesse to load that App.config file.

But here's the problem: The App.config file contains custom config section handler, like this:

<configuration>

  <configSections>
    <sectionGroup name="myGroup">
        <section name="MySection" type="MyNamespace.MyHandler.MySection, MyNamespace.MyHandler"/>
        ...
    </sectionGroup>
  </configSections>
  ...
</configuration>

Whenever the App.config file is read, the I get an exception saying that the MyNamespace.MyHandler assembly cannot be found, although it sits in the same folder as the MyDll.dll.config file being read:

System.TypeInitializationException: The type initializer for 'MyNamespace.MyHandler.MySection' threw an exception. ---> System.Configuration.ConfigurationErrorsException: An error occurred creating the configuration section handler for myGroup/MySection: Could not load file or assembly 'MyNamespace.MyHandler' or one of its dependencies. The system cannot find the file specified

I can see that the system looks for this file in the same folder where the executable that is loading my DLL is located. However, I do not want to copy my files into this third party directory or vice versa.

Is there a way to specify where the system should look for the DLLs to interpret the App.config file? A general solution or a FitNesse-specific solution would both work for me.

Thanks a lot in advance for any help!

Upvotes: 2

Views: 2027

Answers (2)

Jan
Jan

Reputation: 2490

Here's another solution we found ourselves. While the solution presented by Gregor S. indeed seems to enable us to read the App.config, we run into other problems regarding the working directory later. So what we are doing now, is adding the FitNesse Runner application as a link to our project, so that it is picked up from its original location and copied to our test application's folder before it is executed.

It's not nice, but it works.

Upvotes: 0

Gregor Slavec
Gregor Slavec

Reputation: 4904

You could try using the runtime section as explained here:

http://kbalertz.com/897297/consume-assemblies-located-folder-different-application-folder-Visual-Basic.aspx

Upvotes: 1

Related Questions