简体   繁体   English

将ASP.NET 4 App dll进行卷影复制,但改为加载bin dll

[英]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. 在大型asp.net 4应用程序中存在一个非常奇怪的问题。 IIS will sometimes load modules not from the shadow copy location but instead the bin directory where the dlls are originally sourced from. IIS有时不是从卷影副本位置加载模块,而是从dll最初来自的bin目录加载。

Does anyone know how the IIS module loading works and whether this is normal behaviour or a bug? 有谁知道IIS模块加载的工作方式,这是正常现象还是错误?

Problems this is causing us 这是导致我们的问题

  • In dev; 在开发中; the respective dlls get locked in the bin folder meaning that msbuild cannot replace it on build. 相应的dll被锁定在bin文件夹中,这意味着msbuild无法在构建时替换它。
  • this is causing us a particularly nasty (and difficult to find) issue (which we are working around with a hack) where we get TypeMismatchException in nhibernate queryovers 这导致我们遇到一个特别令人讨厌(且很难找到)的问题(正在与黑客一起解决),其中我们在nhibernate queryovers中获取TypeMismatchException

Notes 笔记

  • ASP.NET 4 application running on Win7 & WinServer2008R2, IIS 7.5, multiple projects using MVC3, MVC4, WebForms, WebApi 在Win7和WinServer2008R2,IIS 7.5上运行的ASP.NET 4应用程序,使用MVC3,MVC4,WebForms,WebApi的多个项目
  • Module information sourced by attaching VS debugger and inspecting loaded modules 通过附加VS调试器并检查加载的模块而获得的模块信息
  • If I IISRESET and clear the temp asp.net files folder then spool up the application then the dlls are all copied to the shadow copy location and are then loaded from there. 如果我IISRESET并清除temp asp.net文件文件夹,然后将应用程序后台处理,则dll将全部复制到卷影复制位置,然后从那里加载。 If I then IISRESET again and spool up the application the modules are loaded from the bin location instead of the shadow copy location 如果我然后再次执行IISRESET并后台处理应用程序,则会从bin位置而不是卷影复制位置加载模块
  • This only affects project dependencies of the web project the entry point is always loaded from the shadow copy location. 这仅影响Web项目的项目依赖关系,始终从卷影副本位置加载入口点。 IE Proj.Web will load from shadow copy location, a project dependency of that Proj.BusinessLogic & Proj.DataAccess will load from the bin folder, external dependencies (automapper, glimpse, etc) will load from the shadow copy location. IE Proj.Web将从卷影副本位置加载,该Proj.BusinessLogicProj.DataAccess的项目依赖项将从bin文件夹加载,外部依赖项(自动映射器,瞥见等)将从卷影副本位置加载。
  • We are not overriding any app pool or app domain configuration in either code, web.config or IIS config (default settings). 我们不会在代码web.config或IIS config(默认设置)中覆盖任何应用程序池或应用程序域配置。
  • Can't find anywhere that module loading or app startup is verbosely logged to. 无法找到详细记录了模块加载或应用启动的任何位置。

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. 在我们的一些开发人员经过一番努力之后,我们发现这是由于我们在扫描dll进行nhibernate配置时所造成的。

When we were explicitly loading the dlls from code we were misusing the Assembly helper methods. 当我们从代码中显式加载dll时,我们滥用了Assembly helper方法。 Instead of using Assembly.LoadFrom(assemblyPath) we were using Assembly.LoadFile(assemblyPath) . 而不是使用Assembly.LoadFrom(assemblyPath)而是使用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. 这些方法之间存在许多差异,此处相关的是LoadFile()加载指定的文件,而LoadFrom()将应用逻辑以从其他位置(如temp,cache或GAC LoadFrom()查找程序集。 See this question for more details of the differences. 有关差异的更多详细信息,请参见此问题

Anyway, after changing this single line of code, all of our problems disappeared. 无论如何,在更改了这一行代码之后,我们所有的问题都消失了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM