May 3, 2011

The dreaded 'has not been pre-compiled' message

If you're "in-the-know" you've probably since stepped up to Web Application projects over the more ASP Classic-style Web Site projects. Along with that comes the Web Deployment Projects, which have had a version out for every Visual Studio since 2005. This project is basically a nice(r) front-end to MSBuild that lets you pre-compile the app, leaving only .aspx marker files instead of the raw html/code.

During your travels, you're bound to come across the infinitely misleading error after deploying your site using said deployment project:

The file 'MyPage.aspx' has not been pre-compiled, and cannot be requested.

Your first thought, like all of us, is "Umm, yes it has been pre-compiled. I just built the deployment for it, the page is a marker file, everything is in a .dll in the bin folder!"

And you're right, the page was properly pre-compiled. So why are you still getting this message?

It's a misleading one because generally the problem involves missing references on your deployment server/location. Something isn't installed into the GAC that your app is expecting to be there or you didn't include all assemblies in the build (Copy Local was set to false or something like that). What happens is the ASP.NET engine locates the marker, goes to find it in the assembly, fails to load it (because of missing reference) and thus is left with nothing, so it ends up throwing a "cannot find file" type error. That's not entirely true, but it doesn't know the difference. It went to load a page and got back nothing (because the loader failed to load it due to the missing assembly references).

Nine times out of ten it's a missing reference, though. Make sure all of the non-framework assemblies you've added have Copy Local set to true. If you've installed stuff into your development machine's GAC (ASP.NET AJAX Extensions was a common one back in the day) that hasn't been installed into the deployment server's GAC, either install it or include the assembly outright instead of relying on the GAC. ReportViewer references often cause this too since each Visual Studio version uses a different one (and generally doesn't include older versions).

No comments:

Post a Comment