asp.netdlliis-7shadow-copy

ASP.NET 4 App dll is shadow copied but bin dll is loaded instead


Having a very odd issue with a large asp.net 4 application. IIS will sometimes load modules not from the shadow copy location but instead the bin directory where the dlls are originally sourced from.

Does anyone know how the IIS module loading works and whether this is normal behaviour or a bug?

Problems this is causing us

Notes


Solution

  • Discovered the root cause of this issue a few weeks ago, posting now to hopefully help anyone who suffers from anything similar.

    After a couple aha moments from a few of our devs we discovered that this was self-inflicted by the way that we were scanning dlls for nhibernate configurations.

    When we were explicitly loading the dlls from code we were misusing the Assembly helper methods. Instead of using Assembly.LoadFrom(assemblyPath) we were using Assembly.LoadFile(assemblyPath). There are a bunch of differences between these methods, relevant here is that LoadFile() loads the specified file whereas LoadFrom() will apply logic for finding the assembly from other locations such as temp, cache or GAC. See this question for more details of the differences.

    Anyway, after changing this single line of code, all of our problems disappeared.