I have an ASP.NET MVC 5 web application. In every .cshtml view file i get the following error for Viewbag: One or more types required to compile a dynamic expre
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());
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 do not have this problem when running VS 2012 as administrator.
Otherwise, what worked for me:
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>
set copy local = true
properties for System.Core
and Microsoft.CSharp