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

时间:2015-05-14 22:44:30

标签: c# gmail-api

我收到错误:

  

"无法加载文件或程序集&System; Net.Net.Http.Primitives,Version = 4.2.22.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'或其中一个依赖项。系统找不到指定的文件。":" System.Net.Http.Primitives,Version = 4.2.22.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a"}

运行以下代码:

        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,
        });

有关如何解决此错误的任何想法?

我尝试根据this answer从Nuget更新Http客户端库的安装,但是无法安装错误:无法添加对System.Net.Http的引用,请确保它在全局程序集缓存。我不知道全局程序集缓存是什么,或者如何确保它在那里。这个问题有解决方案吗?

2 个答案:

答案 0 :(得分:5)

尝试通过转到工具来更新NuGet包管理器 - &gt;扩展程序和更新 - &gt;更新 - &gt; NuGet包管理器 - &gt;更新

卸载包并重新安装。

答案 1 :(得分:0)

由于您已经在代码中拥有秘密,因此可以执行以下操作:

// 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();