从.NET 3.5到4.0:Web应用程序崩溃,因为没有发现未使用的组件

问题描述:

一个网站我正在使用一个第三方组件,让我们说A.DLL。本届大会还加载了一些操作的另一个程序集B。使用我的网站做了一个并不需要b。在所有的,而我没有B.DLL。

A website I'm working on is using a third-party assembly, let's say A.dll. This assembly A also loads another assembly B for some operations. The use that my website makes out of A doesn't require B at all, and I don't have B.dll.

这是从来没有当我是打靶.NET 3.5中的问题,但现在我想移动到.NET 4中,我得到一个错误。当我认为我的网站在浏览器中,我得到:无法加载文件或程序集B.DLL[...]。如果我把B.DLL在bin目录中,它工作正常。

This was never a problem when I was targetting .NET 3.5, but now that I'm trying to move to .NET 4, I get an error. When I view my website in the browser, I get: "Could not load file or assembly 'B.dll' [...]". If I put B.dll in the bin directory, it works fine.

不过,我不希望部署B.DLL,我不知道是什么让.NET 4尝试加载该程序集,而该网站不使用的需要的任何功能。我感到迷惑,同样的code正常工作的.NET 3.5。我猜它会尝试加载的所有程序集提前,即使它不会被使用。我在寻找一些配置和编译器标志,该标志将prevent此行为。任何指针?

However, I don't want to deploy B.dll and I don't know what makes .NET 4 try to load that assembly while the website does not use any function of A that requires it. I'm mystified as the same code works fine on .NET 3.5. I'm guessing that it tries to load all assemblies in advance, even if it won't be used. I'm looking for some configuration or compiler flag that would prevent this behavior. Any pointers?

我想通过省略的细节和原因,我不希望B部署,等等。请让我知道,如果我提供的资料没有给出一个明确的拍摄问题,以简化我的问题。谢谢!

I tried to simplify my problem by omitting details and reasons why I don't want B deployed, etc. Please let me know if the information I've given doesn't give a clear shot of the problem. Thanks!

编辑:

堆栈跟踪

[FileNotFoundException异常:未能加载文件或程序集B,版本= 15.4.0.0,文化=中性公钥= 1a5b964d6f0fbeab或它的某一个依赖。该系统找不到指定的文件。]

[FileNotFoundException: Could not load file or assembly 'B, Version=15.4.0.0, Culture=neutral, PublicKeyToken=1a5b964d6f0fbeab' or one of its dependencies. The system cannot find the file specified.]

_Default.Page_Load(对象发件人,EventArgs e)在C:\用户\鲍勃\桌面\的WebSite1 \ Default.aspx.cs:15

_Default.Page_Load(Object sender, EventArgs e) in c:\Users\bob\Desktop\WebSite1\Default.aspx.cs:15

错误帮助(IntPtr的FP,对象o,对象T,EventArgs的)+14 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(对象发件人,EventArgs的)+35 System.Web.UI.Control.OnLoad(EventArgs的)+91 System.Web.UI.Control.LoadRecursive()+74 System.Web.UI.Page.ProcessRequestMain(布尔includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint)2207

System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35 System.Web.UI.Control.OnLoad(EventArgs e) +91 System.Web.UI.Control.LoadRecursive() +74 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207

程序集加载跟踪

=== pre-绑定状态信息=== 日志:用户=先令 日志:显示名称= B,版本= 15.4.0.0,文化=中性公钥= 1a5b964d6f0fbeab  (完全限定) 日志:应用平台=文件:/// C:/用户/鲍勃/桌面/的WebSite1 / LOG:初始PrivatePath = C:\用户\鲍勃\桌面\的WebSite1 \ BIN 调用汇编:A,版本= 16.0.0.0,文化=中性公钥=空

=== Pre-bind state information === LOG: User = bob LOG: DisplayName = B, Version=15.4.0.0, Culture=neutral, PublicKeyToken=1a5b964d6f0fbeab (Fully-specified) LOG: Appbase = file:///C:/Users/bob/Desktop/WebSite1/ LOG: Initial PrivatePath = C:\Users\bob\Desktop\WebSite1\bin Calling assembly : A, Version=16.0.0.0, Culture=neutral, PublicKeyToken=null.

=== 日志:此绑定从default加载上下文。 日志:正在使用应用程序配置文件:C:\用户\鲍勃\桌面\的WebSite1 \ web.config中 日志:使用主机配置文件: 日志:从C使用计算机配置文件:\ WINDOWS \ Microsoft.NET \框架\ v4.0.30319 \ CONFIG \ machine.config中。 日志:后政策参考:B,版本= 15.4.0.0,文化=中性公钥= 1a5b963c6f0fbeab 日志:新的URL文件试图下载:/// C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET文件/网站1 / efdbfea0 / f60231a3 / B.DLL。 日志:新的URL文件试图下载:/// C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET文件/网站1 / efdbfea0 / f60231a3 / B / B.DLL。 日志:新的URL文件试图下载:/// C:/Users/bob/Desktop/WebSite1/bin/B.DLL。 日志:新的URL文件试图下载:/// C:/Users/bob/Desktop/WebSite1/bin/B/B.DLL。 日志:新的URL文件试图下载:/// C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET文件/网站1 / efdbfea0 / f60231a3 / B.EXE。 日志:新的URL文件试图下载:/// C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET文件/网站1 / efdbfea0 / f60231a3 / B / B.EXE。 日志:新的URL文件试图下载:/// C:/Users/bob/Desktop/WebSite1/bin/B.EXE。 日志:新的URL文件试图下载:/// C:/Users/bob/Desktop/WebSite1/bin/B/B.EXE

=== LOG: This bind starts in default load context. LOG: Using application configuration file: C:\Users\bob\Desktop\WebSite1\web.config LOG: Using host configuration file: LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config. LOG: Post-policy reference: B, Version=15.4.0.0, Culture=neutral, PublicKeyToken=1a5b963c6f0fbeab LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/website1/efdbfea0/f60231a3/B.DLL. LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/website1/efdbfea0/f60231a3/B/B.DLL. LOG: Attempting download of new URL file:///C:/Users/bob/Desktop/WebSite1/bin/B.DLL. LOG: Attempting download of new URL file:///C:/Users/bob/Desktop/WebSite1/bin/B/B.DLL. LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/website1/efdbfea0/f60231a3/B.EXE. LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/website1/efdbfea0/f60231a3/B/B.EXE. LOG: Attempting download of new URL file:///C:/Users/bob/Desktop/WebSite1/bin/B.EXE. LOG: Attempting download of new URL file:///C:/Users/bob/Desktop/WebSite1/bin/B/B.EXE.

发现问题;在我们调用组件的方法之一,已经从B.DLL的方法签名值类型。在.NET 4.0中,这将加载B.DLL即使该方法不会被调用。

Found the problem; one of the methods in the assembly we were calling had a value type from B.dll in a method signature. In .NET 4.0, this will load B.dll even if that method is never called.

解决的办法是修改方法签名删除所有引用到B的值类型。

The solution was to modify the method signature to remove all references to B's value types.