从 .NET 3.5 到 4.0:Web 应用程序崩溃,因为找不到未使用的程序集

发布于 2024-09-30 21:42:26 字数 2409 浏览 1 评论 0原文

我正在开发的网站正在使用第三方程序集,例如 A.dll。该程序集 A 还加载另一个程序集 B 来执行某些操作。我的网站使用 A 根本不需要 B,而且我没有 B.dll。

当我以 .NET 3.5 为目标时,这从来都不是问题,但现在我尝试迁移到 .NET 4 时,出现错误。当我在浏览器中查看我的网站时,我得到:“无法加载文件或程序集‘B.dll’[...]”。如果我把 B.dll 放在 bin 目录中,它就可以正常工作。

但是,我不想部署 B.dll,并且我不知道是什么让 .NET 4 尝试加载该程序集,而网站不使用需要它的 A 的任何功能。我很困惑,因为相同的代码在 .NET 3.5 上运行良好。我猜测它会尝试提前加载所有程序集,即使它不会被使用。我正在寻找一些可以防止这种行为的配置或编译器标志。有什么指点吗?

我试图通过省略细节和我不想部署 B 的原因等来简化我的问题。如果我提供的信息不能清楚地说明问题,请告诉我。谢谢!

编辑:

堆栈跟踪

[FileNotFoundException:无法加载文件或程序集“B,Version=15.4.0.0,Culture=neutral,PublicKeyToken=1a5b964d6f0fbeab”或其依赖项之一。系统找不到指定的文件。]

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

System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp 、对象 o、对象 t、EventArgs e) +14 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(对象发送者,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

程序集加载跟踪

=== 预绑定状态信息 === 日志:用户 = bob 日志:显示名称 = B,版本 = 15.4.0.0,文化 = 中性,PublicKeyToken = 1a5b964d6f0fbeab (详细说明) 日志:Appbase = file:///C:/Users/bob/Desktop/WebSite1/ 日志:初始 PrivatePath = C:\Users\bob\Desktop\WebSite1\bin 调用程序集:A,版本=16.0.0.0,文化=中性,PublicKeyToken=null。

=== 日志:此绑定在默认加载上下文中启动。 日志:使用应用程序配置文件:C:\Users\bob\Desktop\WebSite1\web.config 日志:使用主机配置文件: 日志:使用 C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config 中的计算机配置文件。 日志:政策后参考:B,版本=15.4.0.0,文化=中性,PublicKeyToken=1a5b963c6f0fbeab 日志:尝试下载新的 URL 文件:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/website1/efdbfea0/f60231a3/B.DLL。 日志:尝试下载新的 URL 文件:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/website1/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 Files/website1/efdbfea0/f60231a3/B.EXE。 日志:尝试下载新的 URL 文件:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/website1/efdbfea0/f60231a3/B/B.EXE。 日志:尝试下载新的 URL 文件:///C:/Users/bob/Desktop/WebSite1/bin/B.EXE。 日志:尝试下载新的 URL 文件:///C:/Users/bob/Desktop/WebSite1/bin/B/B.EXE。

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.

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.

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?

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!

EDIT:

Stack trace

[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(Object sender, EventArgs e) in c:\Users\bob\Desktop\WebSite1\Default.aspx.cs:15

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

Assembly load trace

=== 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.

===
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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

反差帅 2024-10-07 21:42:26

Default.aspx.cs 第 15 行调用的函数使用 B.dll。

The function called by your Default.aspx.cs on line 15 uses B.dll.

独行侠 2024-10-07 21:42:26

发现问题;我们调用的程序集中的方法之一在方法签名中具有来自 B.dll 的值类型。在 .NET 4.0 中,即使从未调用该方法,也会加载 B.dll。

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

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.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文