为什么我会收到“无法找到编译动态表达式所需的一种或多种类型."? [英] Why am I getting 'One or more types required to compile a dynamic expression cannot be found.'?
问题描述
我有一个从
- .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?
我做了以下事情
- 按照升级步骤
- 在项目/属性/应用程序选项卡中将目标框架设置为 .NET Framwework 4
- 添加了 System.Core 框架 手动
- 添加了 Microsoft.CSharp 框架
- 添加了System.Xml框架
- 添加了System.Xml.Linq框架
- 确保我的 Web.Config 是正确的(它被 Web.Debug.Config 等覆盖)
- 创建了模型、控制器和一个Razor视图
- 创建一个 __Layout.cshtml_
- Followed the upgrade steps
- Set the target framework in the Project/Properties/Application tab to .NET Framwework 4
- Added the System.Core framework manually
- Added the Microsoft.CSharp framework
- Added the System.Xml framework
- Added the System.Xml.Linq framework
- Made sure my Web.Config is correct (it gets written over by Web.Debug.Config, etc)
- Created the model, controller and a Razor View
- 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.
- 在配置文件中,我将
<compilation debug="true">
更改为<compilation debug="true" targetFramework="4.0">
system.web 部分 - 在配置文件中,我将
<providerOption name="CompilerVersion" value="v3.5"/>
更改为<providerOption name="CompilerVersion" value="v4.0"/>
在编译器部分 - 在 Global.asax.cs 中,我将
ViewEngines.Engines.Add(new RazorViewEngine());
添加到Application_Start()
方法
- In the config file I changed
<compilation debug="true">
to<compilation debug="true" targetFramework="4.0">
in the system.web section - In the config file I changed
<providerOption name="CompilerVersion" value="v3.5" />
to<providerOption name="CompilerVersion" value="v4.0" />
in the compilers section - In Global.asax.cs I added
ViewEngines.Engines.Add(new RazorViewEngine());
to theApplication_Start()
method
我认为就是这样.
这篇关于为什么我会收到“无法找到编译动态表达式所需的一种或多种类型."?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!