简体   繁体   中英

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:

  1. The type 'Object' 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'.

  2. The type 'IDisposable' 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'.

  3. 'DropboxClient': type used in a using statement must be implicitly convertible to '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'.

  5. The type 'Object' 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'.

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.

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?

Using package manager console I've installed this package : "Microsoft.NETCore.Portable.Compatibility": "1.0.1" and now there are no errors. I've run this command: 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. This package supports retargeting references to classic reference assemblies (mscorlib.dll, system.dll, etc) to new contract assemblies (System.Runtime.dll, System.IO, etc).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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