Viewbag.Title error: One or more types required to compile a dynamic expression cannot be found. Are you missing a reference?

落爺英雄遲暮 提交于 2019-12-03 11:31:37
algor77

I do not have this problem when running VS 2012 as administrator.

Otherwise, what worked for me:

  1. in root web config have added as recommended reference to correct assembly as child of compilation node <system.web> <compilation debug="true" targetFramework="4.5"> <assemblies> <add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> </assemblies></compilation> </system.web>

  2. set copy local = true properties for System.Core and Microsoft.CSharp

For reference Microsoft.CSharp, change the value of property Copy Local from False to True.

This happened to me after I made a code change on the cshtml page with a syntax error. After correcting the syntax error, the errors persisted. So, I closed the cshtml and re-compiled... success. I reopened the cshtml and the errors were no longer there.

I hope this will help someone. Works for me in VS 2013 with asp.net MVC 5 and .NET 4.6.1

Readding Microsoft.CSharp did not fix the problem. Also, adding System.Core to system.web/compilation/assemblies/ at web.config did not fix too.

I overcame this only this adding System.Web.Mvc to system.web/compilation/assemblies/ section:

<compilation debug="true" targetFramework="4.6.1">
  <assemblies>
      <add assembly="System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  </assemblies>
</compilation>

Rebuilded the solution and red line disappeared.

Add the following to Application_Start() method in global.asax

ViewEngines.Engines.Add(new RazorViewEngine());

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!