开发者

From .NET 3.5 to 4.0: web app crashes because unused assembly is not found

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/efdbfea开发者_Go百科0/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.


The function called by your Default.aspx.cs on line 15 uses 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.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜