使用precompiledMvc​​Engine FindView抛出InvalidOperationException异常并查找查看CSHTML文件 [英] Using PrecompiledMvcEngine FindView throws InvalidOperationException and looks for View cshtml files

查看:233
本文介绍了使用precompiledMvc​​Engine FindView抛出InvalidOperationException异常并查找查看CSHTML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了一个出现InvalidOperationException 当MVC控制器,同时使用试图 FindView precompiledMvc​​Engine

I got an InvalidOperationException when the MVC controller tried to FindView while using the PrecompiledMvcEngine.

使用具有VS2012,MVC4和一台机器上部署到IIS

Using on a machine that has VS2012, MVC4 and deployed to IIS

推荐答案

看着来源$ C ​​$ C后 ControllerBase.FindView ViewEngineCollection.FindView 到<一个href=\"http://aspnetwebstack.$c$cplex.com/SourceControl/changeset/view/b2ed65aea577#src/System.Web.Mvc/VirtualPathProviderViewEngine.cs\"相对=nofollow> VirtualPathProviderViewEngine 以<一个href=\"http://razorgenerator.$c$cplex.com/SourceControl/changeset/view/15452bd849f1#RazorGenerator.Mvc/$p$pcompiledMvcEngine.cs\"相对=nofollow> precompiledMvc​​Engine ,发现 _mappings 在precompiledMvc​​Engine有0(T x的计数反思与开源。 )

After looking at the source code of ControllerBase.FindView to ViewEngineCollection.FindView to VirtualPathProviderViewEngine to PrecompiledMvcEngine, found that _mappings in PrecompiledMvcEngine had a count of 0. (Tx to Reflection and Open source.)

究其原因是,有没有类型可分配在我的项目的DLL来WebPageRenderingBase。在反编译我的DLL,它实际上已经编译好的意见,意见从WebPageRenderingBase延长。

The reason is that there was not Type assignable to WebPageRenderingBase in my project's DLL. On decompiling my dll, it actually had the compiled views, and the views extended from WebPageRenderingBase.

编写单元测试做precompiledMvc​​Engine并加载享有同样的事情后,发现他们正在使用不同版本的WebPageRenderingBase类。 RazorGenerator.Mvc使用System.Web.WebPages V1.0.0.0至precompile在构建时。从加载编译的程序集的类型时,precompiledMvc​​Engine使用System.Web.WebPages V2.0.0.0。通过改变我的MVC csproject在运行时也将加载V1.0.0.0修正这一点。

After writing a unit test to do the same thing that PrecompiledMvcEngine does to load views, found that they are using different versions of the WebPageRenderingBase class. RazorGenerator.Mvc uses System.Web.WebPages v1.0.0.0 to precompile at build time. The PrecompiledMvcEngine uses System.Web.WebPages v2.0.0.0 when loading types from the compiled assembly. Fixed this by changing my MVC csproject to also load v1.0.0.0 at runtime.

变更

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

这捡起来2.0.0.0

which picked up 2.0.0.0 to

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

迫使它总是拿起1.0.0.0。如果要部署precompiled观点与VS2012和MVC4安装一台机器这个问题经常会遇到,在不的csproj文件中指定正确的版本。

forcing it to always pick up 1.0.0.0. This problem will often be faced if you are deploying precompiled views to a machine with VS2012 and MVC4 installed, without specifying the correct version in the csproj file

这篇关于使用precompiledMvc​​Engine FindView抛出InvalidOperationException异常并查找查看CSHTML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆