locked
System.Web.HttpException (0x80004005): The file '/Views/Shared/_Layou.cshtml' has not been pre-compiled, and cannot be requested. RRS feed

  • Question

  • User1295156408 posted

    Hello,

    I have a MVC site (mvc 5.2.3.0 version) installed on a Windows Server 2012 standard, that is working properly for over a year. The last 2 months I have faced repeatedly the following issue.

    I have deployed changes and the site is working perfectly. I should mention that I publish the site pre-compiled. Also the application pool is set to "Always running", so that there is no loading time. After a week (5-7 days) it crushes without having changed (I have validated that there is nothing changed) with the following error: 

    System.Web.HttpException (0x80004005): The file '/Views/Shared/_Layout.cshtml' has not been pre-compiled, and cannot be requested.
       at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)
       at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)
       at System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean throwIfNotFound)
       at System.Web.WebPages.BuildManagerWrapper.ExistsInPrecompiledSite(String virtualPath)
       at System.Web.WebPages.VirtualPathFactoryManager.Exists(String virtualPath)
       at System.Web.WebPages.WebPageExecutingBase.NormalizeLayoutPagePath(String layoutPagePath)
       at System.Web.WebPages.StartPage.set_Layout(String value)
       at System.Web.WebPages.StartPage.ExecutePageHierarchy()
       at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
       at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult)
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult)
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)
       at System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState)
       at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
       at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)
       at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
       at System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)
       at System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState)
       at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
       at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
       at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
       at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
       at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

    I have tried several things to restore it, but nothing is working, change the user to the application pool, restart the machine, IIS and it is major that the site should not crush. So the only way I have found to recover is to rebuild it and redeploy it, the same source code, the dlls are the same, nothing is missing or corrupted.

    I suspect after searching for this, that there is a problem with my mvc dll version. I read that nuget packages might come with updates and that might not always load from the site's folder, so that could make an issue if the downloaded version does not apply to mvc dll in my folder. Could that be the case and if so how can I solve it? (I ask here because all the errors I find is during deploy but in my case deploy solves my problem so I am kind of stuck an how can I solve this?)

    Monday, December 17, 2018 10:56 AM

All replies

  • User1080785583 posted

    I have located a duplicate possible answer, which sounds like missing assembly references in your new layout page.

    https://forums.asp.net/t/956297.aspx?Web+Deployment+Project+has+not+been+pre+compiled+

    Monday, December 17, 2018 6:33 PM
  • User1295156408 posted

    Thanks for the answer but unfortunately this is not my case, since my problem occurs days after deployment. My deployment works and no file is missing i have checked all the files that are in place and not modified.

    Tuesday, December 18, 2018 7:56 AM
  • User1520731567 posted

    Hi sofiasid,

    Here are some possible scenarios that will generate this error:

    1. When we publish the website with the "updateable" check OFF and then copy some files on deployment location that has some markup or code in them. By putting the "updateable" check OFF we instruct the asp.net compiler to compile all the markup and code into dll files so that further on asp.net would not consider runtime compilation of content. But if it needs to (due to the presence of such content) it will throw that error.

    2. The second situation is when we have a web application configured in VS.Net to run directly off IIS (the http project) and then we publish it to the same location again with the "updateable" checked OFF. There will be development files at same location which will cause similar errors.

    3. Another situation is where we have a precompiled website and within the root folder of it we have another folder that has content for another asp.net application but isn¡¯t marked as application in IIS. ASP.Net tracks asp.net applications when running on IIS by virtual directories in IIS marked as applications. A child folder having un-compiled content within a parent application which is precompiled will again cause this error.

    Source: Microsoft Support

    I suggest you could refer to these two similar links:

    https://stackoverflow.com/questions/602117/how-to-fix-asp-net-error-the-file-nnn-aspx-has-not-been-pre-compiled-and-can

    https://stackoverflow.com/a/49869165

    Hope my answer will helpful to you.

    Best Regards.

    Yuki Tao

    Tuesday, December 18, 2018 8:15 AM
  • User1295156408 posted

    Thank you for your answer.

    Well the last link (https://stackoverflow.com/a/49869165) is the one which is similar to me but is not answered and that is why I posted here. 

    I have read all the above but:

    case 1: I have checked already this one, in case of mistake, no files with markup the whole site is pre-build and does not contain any markup.

    case 2: In my case the folder is production and is completely different than my development one, also I manually delete all bin files and views and then copy the new ones. Also this would have crushed during the deployment.

    case 3: I do not have such files, but I am curious, even if I had shouldn't this crush at the first deployment?

    Tuesday, December 18, 2018 8:35 AM