ASP.NET Tips: Loading a DLL out of the bin directory


Question

A customer has created a web project which references a class library project.  When deployed to the local machine the web/classes all work fine.  When deployed to a ‘shared’ IIS site, the class DLLs exist in the /bin folder, but the web page generates an error:

can’t find file “Documents and settings/….”

when trying to access the class DLL.

Is there a special setup to make the web pages look in its /bin folder?

Answer

There isn’t usually anything needed in order to make this scenario work.  But if it isn’t working for you, there are two choices here.  If you are in ASP.NET, most likely the cause is that you don’t have the following entry in the machine.config prior to 2.0 and the root web.config file (in the same folder as machine.config) for 2.0 and later:

<compilation>
  <assemblies>
    <add assembly="*"/>
  </assemblies>
</compilation>

The other way to do this, if you aren’t using ASP.NET, is to add the bin directory to your path for the application.  The way this is accomplished is with the probing element:

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

This is documented here: <probing> Element

There has been a situation where neither of these worked.  We are still researching that situation and I will update this post when we have another solution.

Comments (8)

  1. Hi,

    I’ve been trying to figure something very like this. But in my case the probing solutions won’t work as I’m developing an addin based solution and wanted to deploy the addon applications in custom folders like ABC/bin and ABCD/bin.

    I’ve tried Assembly.LoadFile and such but although the assembly gets loaded into the domain it looks like it doesn’t get loaded into the ASP.Net page compiler domain.

    Any ideas about this scenario?

  2. tomchris says:

    Alexandre,

    So can you explain to me what you mean by that?  Where does it need to be that it isnt’?  What error do you see?

  3. My folder layout is something like this:

    App

    App/bin

    App/addins/addin1

    App/addins/addin1/bin

    App/addins/addin2

    App/addins/addin2/bin

    And I wanted the main application to load the dlls inside the addin1/bin and addin2/bin so I could execute the addins.

    Im my case, the addins are .ascx files and the bin folder contains the generated assemblies from the code behind files.

    Using AppDomain.Load or Assembly.LoadFile effectively loads the assemblies into the current AppDomain but actually using Page.LoadControl throws an exception that I can’t recall now but I’m sure its the same when you try to browse a page if the code behind assembly is not present.

  4. My favorite links from the last week (20/07/2008 – 26/07/2008)

  5. My favorite links from the last week – 5th Week of July 2008

  6. John Doe says:

    By inspecting the fusion log we found out that <probing> does NOT work if the <configuration> Tag inside web.config includes the xlmns="http://schemas.microsoft.com/.NetConfiguration/v2.0&quot; attribute.

  7. arthur_pham says:

    I have exactly the same needs. I need to load the assemblies from the addin/bin folder. But couldn’t handle how now.

    The thing I am doing is copy them all to the App’s bin directory. But this isn’t nice to mix them all together.

    Anyone as a solution yet?

  8. Warren Tang says:

    CodehighlightingproducedbyActiproCodeHighlighter(freeware)http://www.CodeHighlighter.com/–