为什么我会得到'编译一个动态的前pression所需的一个或多个类型不能被发现。“? [英] Why am I getting 'One or more types required to compile a dynamic expression cannot be found.'?

查看:155
本文介绍了为什么我会得到'编译一个动态的前pression所需的一个或多个类型不能被发现。“?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我从

更新项目

  • .NET 3.5 MVC V2为

  • .NET 4.0 MVC V3

编译我得到一个错误,当我尝试使用或设置 @ ViewBag.Title 属性。


  

要编译一个动态的前pression所需的一个或多个类型不能被发现。
  你缺少Microsoft.CSharp.dll和System.Core.dll参考?


我做了以下


  1. 沿袭升级步骤

  2. 设置目标框架中的项目/属性/应用程序选项卡的 .NET Framwework 4

  3. 新增了的 System.Core程序的框架<一个href=\"http://connect.microsoft.com/VisualStudio/feedback/details/525663/cannot-remove-system-core-dll-reference-from-a-vs2010-project\">manually

  4. 新增了的 Microsoft.CSharp 的框架

  5. 新增了的的System.Xml 的框架

  6. 新增了的 System.Xml.Linq的的框架

  7. 确信我的的Web.Config 的是正确的(它得到由Web.Debug.Config改写等)

  8. 在创建的模式控制器的和一个剃须刀的查看

  9. 创建一个_ Layout.cshtml

我在茫然,我还能怎么办?

编辑:

我在GAC桂注意到有System.Core程序3.5.0.0,但没有System.Core程序4.0.0.0。这是否意味着它越来越困惑,并依然采用previous版本?还是我误解了GAC?

编辑:

我的web.config看起来如下:

  ...
&LT;编译调试=真正的&GT;
    &LT;&集会GT;
        &LT;添加组件=System.Core程序,版本= 4.0.0.0,文化=中性公钥= B77A5C561934E089/&GT;
        &LT;添加组件=System.Data.DataSetExtensions,版本= 3.5.0.0,文化=中性公钥= B77A5C561934E089/&GT;
        &LT;添加组件=System.Data.Linq程序,版本= 3.5.0.0,文化=中性公钥= B77A5C561934E089/&GT;
        &LT;添加组件=System.Web.Abstractions,版本= 4.0.0.0,文化=中性公钥= 31BF3856AD364E35/&GT;
        &LT;添加组件=System.Web.Extensions程序,版本= 3.5.0.0,文化=中性公钥= 31BF3856AD364E35/&GT;
        &LT;添加组件=System.Web.Helpers,版本= 1.0.0.0,文化=中性公钥= 31BF3856AD364E35/&GT;
        &LT;添加组件=System.Web.Mvc,版本= 3.0.0.0,文化=中性公钥= 31BF3856AD364E35/&GT;
        &LT;添加组件=System.Web.Routing,版本= 4.0.0.0,文化=中性公钥= 31BF3856AD364E35/&GT;
        &LT;添加组件=System.Web.WebPages,版本= 1.0.0.0,文化=中性公钥= 31BF3856AD364E35/&GT;
        &LT;添加组件=System.Xml.Linq的,版本= 3.5.0.0,文化=中性公钥= B77A5C561934E089/&GT;
    &LT; /组件&GT;
&LT; /编译&GT;
....
&LT;网页和GT;
    &LT;控制与GT;
    &LT;添加标签preFIX =ASP的命名空间=System.Web.UI程序组件=System.Web.Extensions程序,版本= 3.5.0.0,文化=中性公钥= 31BF3856AD364E35/&GT;
    &LT;添加标签preFIX =ASP的命名空间=System.Web.UI.WebControls集结号=System.Web.Extensions程序,版本= 3.5.0.0,文化=中性公钥= 31BF3856AD364E35/&GT;
&LT; /控制&GT;
&LT;&命名空间GT;
        &LT;添加命名空间=System.Web.Helpers/&GT;
        &LT;添加命名空间=System.Web.WebPages/&GT;
    &LT;添加命名空间=System.Web.Mvc/&GT;
    &LT;添加命名空间=System.Web.Mvc.Ajax/&GT;
    &LT;添加命名空间=System.Web.Mvc.Html/&GT;
        &LT;添加命名空间=System.Web.Routing/&GT;
    &LT;添加命名空间=System.Linq的/&GT;
    &LT;添加命名空间=System.Collections.Generic/&GT;
&LT; /命名空间&GT;
&LT; /页&GT;
....


解决方案

好,我知道了下面的步骤工作。


  1. 在配置文件我改变&LT;编译调试=真正的&GT; &LT;编译调试=真targetFramework = 4.0&GT; 在system.web节

  2. 在配置文件我改变&LT; providerOption NAME =CompilerVersionVALUE =V3.5/&GT; &LT; providerOption NAME =CompilerVersionVALUE =V4.0/&GT; 在编译器的部分

  3. 在Global.asax.cs中我加了 ViewEngines.Engines.Add(新RazorViewEngine()); 的Application_Start()

,我认为这是它。

I had a project that I've updated from

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

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

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?

I have done the following

  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

I'm at loss as to what else to do?

EDIT:

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?

EDIT:

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. 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

and I think that was it.

这篇关于为什么我会得到'编译一个动态的前pression所需的一个或多个类型不能被发现。“?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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