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

前端 未结 5 1664
生来不讨喜
生来不讨喜 2021-02-14 01:03

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

相关标签:
5条回答
  • 2021-02-14 01:43

    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.

    0 讨论(0)
  • 2021-02-14 01:43

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

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

    0 讨论(0)
  • 2021-02-14 01:46

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

    0 讨论(0)
  • 2021-02-14 01:54

    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.

    0 讨论(0)
  • 2021-02-14 01:58

    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

    0 讨论(0)
提交回复
热议问题