简体   繁体   English

Nuget错误:无法添加对System.Net.Http的引用

[英]Nuget Error: Failed to add reference to System.Net.Http

I am getting an error: 我收到一个错误:

"Could not load file or assembly 'System.Net.Http.Primitives, Version=4.2.22.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.":"System.Net.Http.Primitives, Version=4.2.22.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"} “无法加载文件或程序集'System.Net.Http.Primitives,版本= 4.2.22.0,区域性=中性,PublicKeyToken = b03f5f7f11d50a3a”或其依赖项之一。系统找不到指定的文件。”:“ System.Net .Http.Primitives,版本= 4.2.22.0,文化=中性,PublicKeyToken = b03f5f7f11d50a3a“}

running the following code: 运行以下代码:

        base.Initialize(name, config);
        _emailAddress = Settings.EmailAddress;
        string clientSecret = Settings.ClientSecret;
        string clientId = Settings.ClientId;
        Task<UserCredential> tCredential;
        ClientSecrets clientSecrets = new ClientSecrets {ClientId = clientId, ClientSecret = clientSecret};
        tCredential = GoogleWebAuthorizationBroker.AuthorizeAsync(
            clientSecrets,
            Scopes,
            "user",
            CancellationToken.None);
        UserCredential credential;
        try
        {
            credential = tCredential.Result;
        }
        catch (Exception ex)
        {
            throw;
        }
        _service = new GmailService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = "Draft Sender", //applicationName,
        });

Any ideas on how to resolve this error? 关于如何解决此错误的任何想法?

I tried updating the install of the Http Client Libraries from Nuget according to this answer , but that failed to install with the error: Failed to add reference to System.Net.Http, please make sure it is in the global assembly cache. 我尝试根据此答案从Nuget更新Http客户端库的安装,但安装失败,并显示以下错误:无法添加对System.Net.Http的引用,请确保它在全局程序集缓存中。 I don't know what the global assembly cache is, or how to make sure it is in there. 我不知道全局程序集缓存是什么,或者如何确保它在其中。 Is there a solution to this problem? 有解决这个问题的方法吗?

Try Updating your NuGet package manager by going to Tools -> Extensions and Updates -> Updates -> NuGet Package Manager -> Update. 通过转到工具->扩展和更新->更新-> NuGet软件包管理器->更新,尝试更新您的NuGet软件包管理器。

And the uninstall package and install again. 然后卸载软件包并重新安装。

Since you already have the secret in your code, you could do something like: 由于您的代码中已经包含秘密,因此您可以执行以下操作:

// Create OAuth Credential.
UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
    new ClientSecrets
    {
        ClientId = "CLIENT_ID",
        ClientSecret = "CLIENT_SECRET"
    },
    new[] { GmailService.Scope.GmailModify },
    "user",
    CancellationToken.None).Result;

// Create the service.
var service = new GmailService(new BaseClientService.Initializer()
{
    HttpClientInitializer = credential,
    ApplicationName = "Draft Sender",
});

ListDraftsResponse draftsResponse = service.Users.Drafts.List("me").Execute();

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

相关问题 参考问题system.net.http nuget包4.3.1可能无法加载system.net.http 4.1.1 - reference problems system.net.http nuget package 4.3.1 coul not load system.net.http 4.1.1 无法添加对&#39;System.Net.Http&#39;的引用。 请确保它在全局程序集缓存中 - Failed to add reference to 'System.Net.Http'. Please make sure that it is in the Global Assembly Cache Visual Studio 强制在参考程序集中使用 System.Net.Http 而不是 Nuget 中指定的那个 - Visual Studio forces use System.Net.Http in Reference Assembly rather than the one specified in Nuget 无法从Nuget安装Package System.Net.Http - Can't Install Package System.Net.Http from Nuget 我应该使用 System.Net.Http Nuget 包吗? - Should I use the System.Net.Http Nuget Package? 为什么我不能在System.Net.Http引用的解决方案中使用System.Net.Http包? - Why I can not use System.Net.Http package in a solution with System.Net.Http reference? System.Net.Http-添加的参考*始终*显示警告三角形 - System.Net.Http - Reference added *always* shows warning triangle 如何在WP8中引用System.Net.Http? - How to reference System.Net.Http in WP8? 分发System.Net.Http - Distributing System.Net.Http 抓取时遗漏“ System.Net.Http”错误 - Missing `System.Net.Http' error when I scrape
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM