ELMAH dll or custom assembly with modules breaking ImageVault UI in EPiServer 7.5 website

Some time ago I ran into some problems getting Meriwork‘s ImageVault to function on an EPiServer 7.5 website together with the ELMAH logging tool. Today I experienced the same thing, but this time with my project’s own custom Core assembly; I thought that it might be useful to write a short note about it.

The problem appears when either surfing to the ImageVault UI (for instance http://{site}/imagevault) or clicking on the EPiServer global menu button ImageVault (which will try to access http://{site}/EPiServer/ImageVault.AddOn.EPiCMS7/OnlineCenterMenu.aspx). The exception will look something like the following.

Server Error in '/ImageVault' Application.

Could not load file or assembly 'MyProject.Core' or one of its dependencies. The system cannot find the file specified.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'MyProject.Core' or one of its dependencies. The system cannot find the file specified.

To be able to find the source of this, I temporarily turned on the assembly bind failure logging (start your regedit and add a registry DWORD value [HKLM\Software\Microsoft\Fusion!EnableLog] and set it to 1). Note that there are some performance penalty associated with doing this. This showed me that ImageVault was in fact looking for my assembly MyProject.Core within it’s own installation directory’s binary folder.

What I had done to cause this, was adding a custom HttpModule to the web.config file for a redirect engine that I was working on.

<configuration>
  <system.webServer>
    <modules>
      <add name="RedirectModule"
           type="MyProject.Core.{..}.RedirectModule, MyProject.Core" />

This made my redirect module work, but it messed up things for ImageVault. In the same manner, the ELMAH problem was caused by the three ELMAH modules ErrorLog, ErrorMail and ErrorFilter.

      <add name="ErrorLog"
           type="Elmah.ErrorLogModule, Elmah"
           preCondition="managedHandler"/>
      <add name="ErrorMail"
           type="Elmah.ErrorMailModule, Elmah"
           preCondition="managedHandler"/>
      <add name="ErrorFilter"
           type="Elmah.ErrorFilterModule, Elmah"
           preCondition="managedHandler"/>

Disabling HttpModules for specific locations

Luckliy, it’s possible to have HttpModules not run for certain locations through a simple change in the web.config file. So by adding a removal entry to the locations /imagevault as well as /episerver I was able to make ImageVault not go look for them; in the same manner it is possible to fix the ELMAH issue.

<location path="EPiServer">
  <system.webServer>
    <modules>
      <remove name="RedirectModule"/>
    </modules>
<location path="imagevault">
  <system.webServer>
    <modules>
      <remove name="RedirectModule" />
      <remove name="ErrorLog" />
      <remove name="ErrorMail" />
      <remove name="ErrorFilter" />
    </modules>
<location path="imagevaultidentity">
  <system.webServer>
    <modules>
      <remove name="RedirectModule" />
      <remove name="ErrorLog" />
      <remove name="ErrorMail" />
      <remove name="ErrorFilter" />
    </modules>