Using PrecompiledMvcEngine FindView raises an InvalidOperationException and searches for cshtml View files

I received an InvalidOperationException when the MVC tried FindView using PrecompiledMvcEngine .

Use on a machine with VS2012, MVC4, and deployment in IIS

0
asp.net-mvc-3 razorgenerator precompile
Feb 20 '13 at 3:40
source share
1 answer

Looking at the source code of ControllerBase.FindView on ViewEngineCollection.FindView on VirtualPathProviderViewEngine on PrecompiledMvcEngine , I found that _mappings in PrecompiledMvcEngine has a score of 0. (Tx to Reflection and Open source.)

The reason is because in my project DLL there was no type assigned by WebPageRenderingBase. When decompiling my dll, there were actually compiled views, and the views were extended from WebPageRenderingBase.

After writing a unit test, to do the same thing as PrecompiledMvcEngine for loading views, I found that they use different versions of the WebPageRenderingBase class. RazorGenerator.Mvc uses System.Web.WebPages v1.0.0.0 to precompile during build. PrecompiledMvcEngine uses System.Web.WebPages v2.0.0.0 when loading types from a compiled assembly. Fixed this by modifying my MVC csproject to load v1.0.0.0 at runtime.

Modified

  <Reference Include="System.Web.WebPages" /> 

which raised 2.0.0.0 to

  <Reference Include="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" /> 

making him always pick up 1.0.0.0. This problem often occurs if you deploy precompiled views on a machine with VS2012 and MVC4 installed without specifying the correct version in the csproj file

+1
Feb 20 '13 at 3:43
source share



All Articles