简体   繁体   English

将代码移植到ASP.NET Core时缺少引用

[英]Missing references when porting code to ASP.NET Core

I'm using a DropboxClient object in an MVC project and is working fine, but I need to use it in ASP.NET Core, and when I try to use exactly the same code in ASP.NET Core I'm getting some compile time errors, these are the errors: 我在MVC项目中使用DropboxClient对象并且工作正常,但我需要在ASP.NET Core中使用它,当我尝试在ASP.NET Core中使用完全相同的代码时,我得到一些编译时间错误,这些是错误:

  1. The type 'Object' is defined in an assembly that is not referenced. “Object”类型在未引用的程序集中定义。 You must add a reference to assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes'. 您必须添加对程序集'mscorlib,Version = 2.0.5.0,Culture = neutral,PublicKeyToken = 7cec85d7bea7798e,Retargetable = Yes'的引用。

  2. The type 'IDisposable' is defined in an assembly that is not referenced. “IDisposable”类型在未引用的程序集中定义。 You must add a reference to assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes'. 您必须添加对程序集'mscorlib,Version = 2.0.5.0,Culture = neutral,PublicKeyToken = 7cec85d7bea7798e,Retargetable = Yes'的引用。

  3. 'DropboxClient': type used in a using statement must be implicitly convertible to 'System.IDisposable' 'DropboxClient':在using语句中使用的类型必须可以隐式转换为'System.IDisposable'

  4. The type 'Task<>' is defined in an assembly that is not referenced. “任务<>”类型在未引用的程序集中定义。 You must add a reference to assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes'. 您必须添加对程序集'mscorlib,Version = 2.0.5.0,Culture = neutral,PublicKeyToken = 7cec85d7bea7798e,Retargetable = Yes'的引用。

  5. The type 'Object' is defined in an assembly that is not referenced. “Object”类型在未引用的程序集中定义。 You must add a reference to assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes'. 您必须添加对程序集'mscorlib,Version = 2.0.5.0,Culture = neutral,PublicKeyToken = 7cec85d7bea7798e,Retargetable = Yes'的引用。

I think that all these errors are related to some configuration that I need to do in ASP.net Core, in MVC the code runs without problem. 我认为所有这些错误都与我在ASP.net Core中需要做的一些配置有关,在MVC中代码运行没有问题。

This is the code: 这是代码:

 public IActionResult Index()
        {
            using (DropboxClient client = new DropboxClient("dddddddddddddsdadffsdf343"))
            {
                var full = client.Users.GetCurrentAccountAsync();
                var result = full.Result.Email;
                var other = full.Result.Country;
                var other2 = full.Result.Name;
            }
                return View();
        }

What do I need to change in ASP.net Core in order for this code to run? 为了让这段代码运行,我需要在ASP.net Core中进行哪些更改?

Using package manager console I've installed this package : "Microsoft.NETCore.Portable.Compatibility": "1.0.1" and now there are no errors. 使用包管理器控制台我安装了这个包: "Microsoft.NETCore.Portable.Compatibility": "1.0.1" ,现在没有错误。 I've run this command: install-package Microsoft.NETCore.Portable.Compatibility . 我运行了这个命令: install-package Microsoft.NETCore.Portable.Compatibility I'm copying a short descritpion about this package: 我正在复制关于这个包的简短描述:

Enables compatiblity with portable libraries targeting previous .NET releases like .NET Framework 4.0 and Silverlight. 实现与针对.NET Framework 4.0和Silverlight等早期.NET版本的可移植库的兼容性。 This package supports retargeting references to classic reference assemblies (mscorlib.dll, system.dll, etc) to new contract assemblies (System.Runtime.dll, System.IO, etc). 此程序包支持将对经典引用程序集(mscorlib.dll,system.dll等)的引用重定向到新的协定程序集(System.Runtime.dll,System.IO等)。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM