3

我在 Visual Studio 2012 中遇到了一个大问题。每当我启动一个 ASP.Net MVC4 项目时,我都会收到以下错误:

Cannot convert lambda expression to type 'System.Linq.Expressions.Expression<System.Func<Carrousel.Web.ViewModels.LoginViewModel,bool>>' because it is not a delegate type

One or more types required to compile a dynamic expression cannot be found. Are you missing a reference?    d:\Visual Studio\Projects\School\Carrousel v2\Carrousel.Presentation\Views\Account\Login.cshtml

The type arguments for method 'System.Web.Mvc.Html.InputExtensions.TextBoxFor<TModel,TProperty>(System.Web.Mvc.HtmlHelper<TModel>, System.Linq.Expressions.Expression<System.Func<TModel,TProperty>>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

当 cshtml 文件中有 ViewBag 和 Html 表单助手等动态表达式时,就会发生这种情况。

我已经搜索了一段时间,我能找到的唯一原因是没有引用 Microsoft.CSharp 和/或 System.Core。但是我在项目中都引用了。

此问题仅在使用 Asp.Net Mvc 4 时出现,在使用 Mvc 3 时一切正常。这个错误发生在我的 Windows 7 和 Windows 8 Enterprise 版本上。我还尝试通过包管理器卸载并重新安装 mvc4。

4

1 回答 1

0

尝试删除并添加对以下程序集的引用:

  Microsoft.Scripting.Core.dll  
  Microsoft.CSharp

  CopyToLocal = true
于 2013-11-13T15:18:23.737 回答