Fix “The File Has Not Been Pre-Compiled, and Cannot Be Requested” in ASP.NET MVC 5
Quick fix. Check whether the deployed application was published as precompiled. If it was, redeploy one complete output from a clean build. Copying a single .cshtml file from a different build can leave it out of sync with compiled artifacts.
This guide applies to ASP.NET MVC 5 on .NET Framework (System.Web.Mvc).
Determine which publishing mode is in use
Look in the IIS application’s actual physical root for PrecompiledApp.config, then check the failed virtual path in the error. The file is a clue that the publish output expects precompiled artifacts. Some publishing modes leave editable markup, while non-updatable deployments can contain marker files in place of the original content. An MVC precompiled deployment differs from merely compiling the controller assembly.
Check that the files came from the same build
Compare the server tree with the publish artifact, including bin, .compiled mapping files if present, any precompilation marker, area views, and relevant configuration. Confirm that the failing path exists under the correct IIS application. A successful homepage with one failing area or view often warrants a file-by-file comparison for that path first.
Deploy the complete publish output
Publish the same configuration to a fresh staging directory. Deploy and test the complete output as a unit using your normal release process. Verify the homepage and the affected view through a staging IIS site before switching traffic. If the application is meant to compile views at runtime, produce a clean runtime-compilation build with the appropriate source views. Removing only the marker file from a precompiled release can leave a mix of incompatible artifacts.
Check the old and new paths in staging
Exercise a normal controller view, a partial rendered by the affected page, and an area view. Check the application’s physical path and deployed release version. If staging succeeds and production fails, compare deployment exclusions and IIS application roots before rebuilding again. Keep the previous complete artifact available so you can restore it if a release fails.
Comments
Post a Comment