Could not load file or assembly App_Web_ * with a precompiled ASP.NET website project

user849924 picture user849924 · Apr 12, 2012 · Viewed 7.2k times · Source

I'm getting this problem on a very specific page and I'm not sure how to fix it. I've already found several SO questions (such as ASP.NET corrupt assembly "Could not load file or assembly App_Web_*" and Could not load file or assembly App_Web_xxxxxxxx or one of its dependencies) and tried their solutions, but to no avail.

To recap, here's what I've tried:

  • Set batch="false" numRecompilesBeforeAppRestart="50" in the web.config

  • Restarted the IIS website that hosts this website

  • Cleared the ASP.NET temporary files in %windir%\Framework64\v4.0.30319\Temporary ASP.NET Files

  • Reployed

... and any combination of the above, but to no avail. It works perfectly fine when I attempt to run the site from VS and when I deploy the website without pre-compilation.

Here are some specs of the enviroment:

  • Pre-compilation is done through a Web Deployment Project. It does not matter if TFS or I did the precompilation: the problem persists

  • .NET version is 4.0.30319

  • AppPool settings: Pipeline mode is Integrated on .NET 4.0

This is the specific error, which occurs when I open Customer.aspx:

Could not load file or assembly 'App_Web_qxcfa0wv, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

This page has registered a control called UserManagement.ascx, located at ~/Controls/UserManagement.ascx.

That control has registered another control called UserDialog.ascx, which is located at ~/Controls/Dialogs/UserControl.ascx.

And that last control uses a control called ~/Controls/User.ascx which encapsulates the data of a user. There are no further dependencies.

According to the stack trace, the error is on line 1 of UserDialog.ascx (The <%@ Control ... %> directive).

I'm at a loss. My guess is that it doesn't work because ~/Controls/Dialogs/UserDialog.ascx requires a control which is in a parent folder, which results in some out of date reference during runtime. Kind of like the problem description in the first SO question.

However, I can't test that simply by excluding the ~/Controls/User.ascx control because then I'm getting circular reference errors in another control which is used in ~/Control/UserDialog.ascx, even though that control doesn't register any other controls, either. Only a namespace registration, which is used by most other controls.

I'd say that the circular reference and the error are related, though, but I can't quite say how. Not without drawing an entire dependency graph.

Any ideas?

Thanks in advance!

Answer

IrishChieftain picture IrishChieftain · Apr 12, 2012

Convert it to a Web Project, seriously. This is a known problem when using libraries and user controls with the website template. I've summed it up here:

ASP.NET: Web Site versus Web Application Project

More information on Rick Strahl's blog (read the comments):

Understanding Page Inheritance in ASP.NET 2.0