简体   繁体   English

您必须添加对程序集 mscorlib 的引用,版本=4.0.0

[英]You must add a reference to assembly mscorlib, version=4.0.0

I'm having some trouble migrating a web project from RC1 to RC2.我在将 web 项目从 RC1 迁移到 RC2 时遇到了一些麻烦。 When I switched, I'm getting a bunch of these errors throughout the project.当我切换时,我在整个项目中遇到了一堆这些错误。

The type 'Func<,>' is defined in an assembly that is not referenced. 'Func<,>' 类型在未引用的程序集中定义。 You must add a reference to assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'您必须添加对程序集 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' 的引用

Looks like all of the linq functions and lambda expressions are not working.看起来所有 linq 函数和 lambda 表达式都不起作用。

This is what my project.json file looks like:这就是我的project.json文件的样子:

  "frameworks": {
    "netcoreapp1.0": {
      "dependencies": {
        "System.Linq": "4.1.0-rc2-24027"
      },
      "imports": [ "net451", "portable-net45+win8" ]
    }
  },
  "dependencies": {
    "NETStandard.Library": "1.5.0-rc2-24027",
    "Microsoft.EntityFrameworkCore": "1.0.0-rc2-final",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-final",
    "System.ComponentModel.Annotations": "4.1.0-*"
  }

Any ideas what this means?任何想法这意味着什么? I've tried running dotnet restore , did not help.我试过运行dotnet restore ,没有帮助。

I had the same issue and adding the following package to my project.json dependencies fixed it for me:我遇到了同样的问题,并将以下包添加到我的project.json依赖项中为我修复了它:

"Microsoft.NETCore.Portable.Compatibility": "1.0.1-rc2-24027",

This package enables compatibility with mscorlib-based PCLs.此软件包可与基于 mscorlib 的 PCL 兼容。

In fact, the problem is an old lib that requires an asp.net 4.0 or 4.5 vesion (less than Core).事实上,问题是一个旧的 lib,它需要一个 asp.net 4.0 或 4.5 版本(小于 Core)。

Microsoft provides a solution for it by installing the fallowing NuGet package. Microsoft 通过安装空闲的 NuGet 包为其提供了解决方案。

Microsoft.NETCore.Portable.Compatibility Microsoft.NETCore.Portable.Compatibility

this way you will be able to run your code with old libs.这样您就可以使用旧库运行您的代码。

I got this error when I created a new project using the template Class Library (.NET Standard) and ported some code into it that I wanted to re-use.当我使用模板类库 (.NET Standard)创建一个新项目并将一些我想重用的代码移植到其中时,我遇到了这个错误。

I created a new project Class Library (.NET Framework) and moved the code there instead and it worked without any issues.我创建了一个新项目类库 (.NET Framework)并将代码移到那里,它没有任何问题。

Delete the .csproj .user as per in the Screenshot present in the solution folder.根据解决方案文件夹中的屏幕截图删除.csproj .user。 Unload the project from solution explorer.从解决方案资源管理器卸载项目。 Reload the project and build it once.重新加载项目并构建一次。 This worked for me.这对我有用。

For MVC 5, you must add 2 references Right click the project, and add reference对于 MVC 5,您必须添加 2 个引用右键单击项目,然后添加引用

Assemblies > Framework组件 > 框架

Add this 2 references添加这 2 个参考

  • System.IdentityModel 4.0.0.0 System.IdentityModel 4.0.0.0
  • System.IdentityModel.Services 4.0.0.0 System.IdentityModel.Services 4.0.0.0

I don't have the rep to comment but Matt Kemp's post lead to my solution .我没有代表发表评论,但 Matt Kemp 的帖子导致了我的解决方案。 In my case it was using a Class Library(.Net Standard) instead of Android Class Library (Xamarin)就我而言,它使用的是类库(.Net Standard)而不是Android 类库(Xamarin)

mscorlib reference is added by default, but it seems to be a visual studio reference issue. mscorlib 参考是默认添加的,但它似乎是一个 Visual Studio 参考问题。 I have deleted my project and created new one then it worked fine.我已经删除了我的项目并创建了一个新项目,然后它工作正常。

I had this error all of a sudden while working in a unit test project.在单元测试项目中工作时,我突然遇到了这个错误。 Tried the suggestions as mentioned before like unloading and reloading the project, rebuild etc. Eventually all it took was a restart of Visual Studio - Did you try to turn it off and on again :-) VS version 16.11.5尝试了之前提到的建议,例如卸载和重新加载项目、重建等。最终只需要重新启动 Visual Studio -您是否尝试将其关闭并再次打开:-) VS 16.11.5 版

Adding this here in the hopes it'll help someone else, though my scenario was not a web project.在此处添加此内容是希望对其他人有所帮助,尽管我的方案不是 web 项目。 When loading a winforms form (designer) I was getting the error Unable to find assembly 'mscorlib I deleted that file's resx file and let the designer re created it.加载 winforms 表单(设计器)时出现错误无法找到程序集'mscorlib 我删除了该文件的 resx 文件并让设计器重新创建它。 This happened after copying a form that was created in a .netframework project to a .net6 project.这发生在将在 .netframework 项目中创建的表单复制到 .net6 项目后。

Again, not related to the OP but this was the closest SO thread I could find to my problem同样,与 OP 无关,但这是我能找到的最接近问题的 SO 线程

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 .Net Framework 您必须添加对程序集 mscorlib 的引用,版本 = 4.0.0.0 - .Net Framework You must add a reference to assembly mscorlib, Version=4.0.0.0 “MarshalByRefObject”类型是在未引用的程序集中定义的。 您必须添加对程序集 &#39;mscorlib, Version=4.0.0.0 的引用 - The type 'MarshalByRefObject' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=4.0.0.0 您必须添加对程序集&#39;mscorlib,Version = 2.0.5.0 ...&#39;的引用C#WP7 XNA - You must add a reference to assembly 'mscorlib, Version=2.0.5.0…' C# WP7 XNA 您必须添加对程序集&#39;WindowsBase,Version = 3.0.0.0的引用 - You must add a reference to assembly 'WindowsBase, Version=3.0.0.0 可移植类库-您必须添加对程序集&#39;System.Net,版本= 2.0.5.0的引用 - Portable Class Library - you must add a reference to assembly 'System.Net, Version=2.0.5.0 “你必须在奇怪的情况下添加对程序集的引用”编译器错误 - “You must add a reference to assembly” compiler error in weird case 您必须添加对程序集“UnityEngine.AndroidJNIModule”的引用 - You must add a reference to assembly 'UnityEngine.AndroidJNIModule VSCode“您必须添加对程序集&#39;netstandard&#39;的引用”但编译正常 - VSCode "you must add a reference to assembly 'netstandard'" but compiles fine 您必须添加对程序集的引用…而无需web.config文件 - You must add reference to assembly… without web.config file 您必须添加参考 - You must add reference
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM