为什么我会收到“无法找到编译动态表达式所需的一种或多种类型."? [英] Why am I getting 'One or more types required to compile a dynamic expression cannot be found.'?

查看:26
本文介绍了为什么我会收到“无法找到编译动态表达式所需的一种或多种类型."?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从

  • .NET 3.5 MVC v2 到
  • .NET 4.0 MVC v3

编译当我尝试使用或设置 @ViewBag.Title 属性时出现错误.

Compiling I get an error when I try to use or set the @ViewBag.Title property.

无法找到编译动态表达式所需的一种或多种类型.您是否缺少对 Microsoft.CSharp.dll 和 System.Core.dll 的引用?

One or more types required to compile a dynamic expression cannot be found. Are you missing references to Microsoft.CSharp.dll and System.Core.dll?

我做了以下事情

  1. 按照升级步骤
  2. 在项目/属性/应用程序选项卡中将目标框架设置为 .NET Framwework 4
  3. 添加了 System.Core 框架 手动
  4. 添加了 Microsoft.CSharp 框架
  5. 添加了System.Xml框架
  6. 添加了System.Xml.Linq框架
  7. 确保我的 Web.Config 是正确的(它被 Web.Debug.Config 等覆盖)
  8. 创建了模型控制器和一个Razor视图
  9. 创建一个 __Layout.cshtml_
  1. Followed the upgrade steps
  2. Set the target framework in the Project/Properties/Application tab to .NET Framwework 4
  3. Added the System.Core framework manually
  4. Added the Microsoft.CSharp framework
  5. Added the System.Xml framework
  6. Added the System.Xml.Linq framework
  7. Made sure my Web.Config is correct (it gets written over by Web.Debug.Config, etc)
  8. Created the model, controller and a Razor View
  9. Create a __Layout.cshtml_

我不知道还能做什么?

我注意到 GAC Gui 中有 System.Core 3.5.0.0 但没有 System.Core 4.0.0.0.这是否意味着它变得困惑并且仍在使用以前的版本?还是我误解了 GAC?

I notice in the GAC Gui there is System.Core 3.5.0.0 but no System.Core 4.0.0.0. Does this mean that its getting confused and is still using the previous version? Or am I misunderstanding the GAC?

我的 web.config 如下所示

My web.config looks as follows

...
<compilation debug="true">
    <assemblies>
        <add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
    </assemblies>
</compilation>
....
<pages>
    <controls>
    <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</controls>
<namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.WebPages"/>
    <add namespace="System.Web.Mvc" />
    <add namespace="System.Web.Mvc.Ajax" />
    <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
    <add namespace="System.Linq" />
    <add namespace="System.Collections.Generic" />
</namespaces>
</pages>
....

推荐答案

好的,我按照以下步骤操作.

Okay I got it working with the following steps.

  1. 在配置文件中,我将 <compilation debug="true"> 更改为 <compilation debug="true" targetFramework="4.0">system.web 部分
  2. 在配置文件中,我将 <providerOption name="CompilerVersion" value="v3.5"/> 更改为 <providerOption name="CompilerVersion" value="v4.0"/> 在编译器部分
  3. 在 Global.asax.cs 中,我将 ViewEngines.Engines.Add(new RazorViewEngine()); 添加到 Application_Start() 方法
  1. In the config file I changed <compilation debug="true"> to <compilation debug="true" targetFramework="4.0"> in the system.web section
  2. In the config file I changed <providerOption name="CompilerVersion" value="v3.5" /> to <providerOption name="CompilerVersion" value="v4.0" /> in the compilers section
  3. In Global.asax.cs I added ViewEngines.Engines.Add(new RazorViewEngine()); to the Application_Start() method

我认为就是这样.

这篇关于为什么我会收到“无法找到编译动态表达式所需的一种或多种类型."?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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