Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not find file PrecompiledApp.config when working with precompiled Razor views and VirtualPathProviders

We have an application using WebForms .aspx files for just about everything. Latley we have been using precompiled RazorViews as a way of getting nicley packeted functionality by simply dropping a new dll in our project. But now we have discoverd that our precompiled views seems to conflict with our VirtualPathProviders.

When loading VirtualPathProviders from external dlls the application tries to load PrecompiledApp.config for all requests (and we don't got it). The providers are loaded with reflection. We have some VirtualPathProviders in the same project as the registration and they work fine but when we register providers from external dlls with HostingEnvironment.RegisterVirtualPathProvider we get this problem.

If we add the file PrecompiledApp.config it tries to get _appstart.cshtml and so on. We have to have all theese files below before getting past the exeption:

  • PrecompiledApp.config
  • _appstart.cshtml
  • _PageStart.cshtml
  • _ViewStart.cshtml
  • Views/_ViewStart.cshtml
  • Views/Shared/_ViewStart.cshtml
  • default.cshtml

We end up in default.cshtml and the rest of the application works. Since we want to use apsx-files as the default this is not an acceptable solution. We are also worried that more problems will appear from this since we have no idea of why this is happening.

We have tried this way of loading our providers but we still get the same error: http://sunali.com/2008/01/09/virtualpathprovider-in-precompiled-web-sites/

The Exception:

Could not find file 'C:\MyApp\PrecompiledApp.config'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.IO.FileNotFoundException: Could not find file 'C:\MyApp\PrecompiledApp.config'.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[FileNotFoundException: Could not find file 'C:\MyApp\PrecompiledApp.config'.]
   System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +12899479
   System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath) +2481
   System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) +229
   System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) +102
   System.Web.Hosting.MapPathBasedVirtualFile.Open() +105
   System.Web.WebPages.BuildManagerWrapper.IsNonUpdatablePrecompiledApp() +157
   System.Web.WebPages.BuildManagerWrapper..ctor(VirtualPathProvider vpp, IVirtualPathUtility virtualPathUtility) +48
   System.Web.WebPages.VirtualPathFactoryManager.<.cctor>b__6() +90
   System.Lazy`1.CreateValue() +12776623
   System.Lazy`1.LazyInitValue() +355
   System.Web.WebPages.ApplicationStartPage.ExecuteStartPage(HttpApplication application) +131
   System.Web.WebPages.WebPageHttpModule.StartApplication(HttpApplication application, Action`1 executeStartPage, EventHandler applicationStart) +98
   System.Web.WebPages.WebPageHttpModule.InitApplication(HttpApplication application) +75
   System.Web.WebPages.WebPageHttpModule.Init(HttpApplication application) +268
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +575
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +352
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +407
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +375

[HttpException (0x80004005): Could not find file 'C:\MyApp\PrecompiledApp.config'.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11700992
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +141
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +4869221

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
like image 683
Sebastian Hoffback Avatar asked May 03 '12 08:05

Sebastian Hoffback


1 Answers

Are you sure that the FileExists of your VirtualPathProvider returns false for PrecompiledApp.config?

The IsNonUpdatablePrecompiledApp flag invokes the FileExists on the vpp before it actually call Open, to prevent your exception from happening.

like image 86
Grimace of Despair Avatar answered Oct 24 '22 11:10

Grimace of Despair