views:

45

answers:

1

I have an assembly that provides the class structure for a custom config section. Is there a way to wire up the config section to point to the assembly in a different directory or does the assembly have to be in the same directory as the consuming application or the GAC? If it CAN be in a different directory, how/where would I specify such?

For Example:

MyConsole.exe
- lib folder
- - The custom config assembly.

EDIT:

Here's my App.config:

<configSections>
        <section name="TestCustomSection" type="TestCustomConfigSections.TestCustomSection, TestCustomConfigSections" />
</configSections>
<TestCustomSection message="Test is a subdirectory test." />

When TestCustomConfigSections.dll is in the same directory as my console app, it works fine. The moment I move it to /lib, it throws an exception when my code calls GetSection("TestCustomSection") because it can't find the file or assembly.

Thanks

+1  A: 

When .NET fusion binds your references it goes through a number of directories when probing for the requested dlls. All of them should be subdirectories of your ApplicationBase. You can see them by examining the fusion log produced by fuslogvw utility. To launch the utility you can open the command prompt from the Visual Studio Tools menu. If this probing process does not find your dll, An exceptions will be thrown

Unless by the moment the probing happens you subscribed to the AppDomain.AssemblyResolve event. In which case you will have a chance to load assembly yourself using Assembly.Load or Assembly.LoadFrom.

Edit

It will look in additional directories only if they are listed in the AppDomainSetup PrivateBinPath property. If you create your domain programatically you can set the property yourself, for the main appdomain you can set it up in your appconfig file:

<configuration>
   <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
         <probing privatePath="bin;bin\subdir;anotherbin"/>
      </assemblyBinding>
   </runtime>
</configuration>

The point I was trying to make the extra directories have to be under your appbase, otherwise they are ignored

mfeingold
I tried using the fuslogvw and it shows my assembly when it's in the same directory as my exe but the moment I move it to a subdirectory it loses it. Based on what you said, it should look at the subdirectories of the ApplicationBase but it seems to not be the case.
JamesEggers
After adding the assemblyBinding item to my config file, it worked out great. Thanks!
JamesEggers