asp.net-mvc 类型“Expression<>”是在未引用的程序集中定义的
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31086850/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The type 'Expression<>' is defined in an assembly that is not referenced
提问by mansoor
In ASP.NET MVC 4.5.2 Framework.
在 ASP.NET MVC 4.5.2 框架中。
after typing
打字后
@Html.LabelFor()
or
@Html.EditorFor()
in view
鉴于
I'm getting Error: The type 'Expression<>' is defined in an assembly that is not referenced.You must add a reference to assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
我收到错误:类型“Expression<>”是在未引用的程序集中定义的。您必须添加对程序集“System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”的引用。
I have added assembly reference System.Core.dll, Version 4.0.0.0, Runtime Version v4.0.30319. and also i did in web.config
我添加了程序集参考 System.Core.dll,版本 4.0.0.0,运行时版本 v4.0.30319。我也在 web.config 中做了
采纳答案by Prashant2008
I have run in the same issue as you, albeit much later. The issue was that I was not able to access Razor views (.cshtml) as I was getting an error stating that I had a missing assembly reference, namely System.Web.Mvc, even though it was in the project references. After investigation, I have noticed that the installed NuGet version was 5.2.3, while the project required 5.2.0. The solution is to downgrade the MVC version.
我和你遇到了同样的问题,虽然晚了很多。问题是我无法访问 Razor 视图 (.cshtml),因为我收到一个错误,指出我缺少程序集引用,即System.Web.Mvc,即使它在项目引用中。经过调查,我注意到安装的NuGet版本是5.2.3,而项目需要5.2.0。解决办法是降级MVC版本。
- Go to Project-> NuGet Package Manager.
- Search for MVC; it's going to be the first result.
- Next is to select downgrade from the drop-down in the details of the NuGet package and submit.
- 转到项目-> NuGet 包管理器。
- 搜索MVC;这将是第一个结果。
- 接下来是在NuGet包的详细信息的下拉列表中选择downgrade并提交。
Confirm all the dialogs and you are ready to go.
确认所有对话框,您就可以开始了。
回答by ctm1988
I am not sure if you are still having this issue or not but i was having the same issue as well.
我不确定你是否仍然有这个问题,但我也有同样的问题。
I was able to find the solutions here
我能够在这里找到解决方案
https://stackoverflow.com/questions/6496223/compilation-error-in-net-4-0-web-config-linq-not-found
https://stackoverflow.com/questions/6496223/compilation-error-in-net-4-0-web-config-linq-not-found
<add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.DataSetExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
I hope this helps..
我希望这有帮助..
回答by Tom Bowers
This error means that Visual Studio is unable to locate the System.Web.Mvc assembly to power its intellisense for Razor views. One or both of the following may be required to fix it.
此错误意味着 Visual Studio 无法找到 System.Web.Mvc 程序集来为其 Razor 视图提供智能感知。可能需要以下一项或两项来修复它。
- Ensure the version of the .NET framework for the compilation property in the main web.config (the one in the website root) is the same as that specified in the project properties.
- 确保主 web.config 中编译属性的 .NET 框架版本(网站根目录中的那个)与项目属性中指定的版本相同。
[root]/Web.config:
[root]/Web.config:
<system.web>
<compilation targetFramework="4.6" />
Project Properties:
项目属性:
- Ensure the version of the MVC assembly specified in the views web.config (the one in the views folder) is the same as the MVC assembly you are using in your project.
- 确保在 views web.config(views 文件夹中的那个)中指定的 MVC 程序集版本与您在项目中使用的 MVC 程序集相同。
[views folder]/web.config:
[视图文件夹]/web.config:
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
MVC Assembly Reference Properties:
MVC 程序集参考属性:
回答by CularBytes
- Close the cshtml file
- Rebuild solution
- Open cshtml file
- Still errors? Restart Visual studio
- Still errors? Use ctm1988's answer
- 关闭 cshtml 文件
- 重建解决方案
- 打开.cshtml文件
- 还是错误?重新启动视觉工作室
- 还是错误?使用 ctm1988 的回答
回答by leyla azari
I have tried most of these, what eventually worked for me was unloading the project, edit the csproj file, and add the following:
我已经尝试了其中的大部分,最终对我有用的是卸载项目,编辑 csproj 文件,并添加以下内容:
<Reference Include="System.Core" />
回答by Robo Burned
Deleting [projectName].csproj.userfile from the project directory helped for me.
从项目目录中删除[projectName].csproj.user文件对我有帮助。
回答by jsanman
I just had the same exact issue and none of the solutions fixed the problem. I had to add this into my web.configwithin System.Web
我只是遇到了同样的问题,但没有一个解决方案解决了这个问题。我不得不将它添加到我的web.config内部System.Web
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
I had removed it when changing some of the configaround.
我在改变config周围的一些时已经将其删除。
回答by Neshta
In my case this message was shown only when Resharper was turned on. I have cleared Resharper cache, restarted VS, turned Resharper off and turned it on again. The message has dissapeared.
就我而言,此消息仅在打开 Resharper 时显示。我已经清除了 Resharper 缓存,重新启动了 VS,关闭了 Resharper 并再次打开了它。消息已消失。
回答by juFo
In Web.config I needed to change:
在 Web.config 我需要改变:
<system.web>
<compilation debug="true" targetFramework="4.7">
to
到
<system.web>
<httpRuntime targetFramework="4.7" />
<compilation debug="true" targetFramework="4.7">
回答by Angel_D
I've had the same problem with missing assembly and it happened that VS2017 build has not copied it properly into the Bin folder. These steps helped me:
我遇到了与缺少程序集相同的问题,而且 VS2017 版本没有将其正确复制到 Bin 文件夹中。这些步骤帮助了我:
- Navigate to the web project's References node
- Find the reference to System.Core
- Open the VS Properties Window
- In the properties window, change Copy Local: False to True
- 导航到 Web 项目的 References 节点
- 找到对 System.Core 的引用
- 打开 VS 属性窗口
- 在属性窗口中,将 Copy Local: False 更改为 True
from this comment: CS0012: The type '#####Any type#####' is defined in an assembly that is not referenced


