1

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"}

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. 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?

Community
  • 1
  • 1
Chris
  • 28,822
  • 27
  • 83
  • 158

2 Answers2

5

Try Updating your NuGet package manager by going to Tools -> Extensions and Updates -> Updates -> NuGet Package Manager -> Update.

And the uninstall package and install again.

Michal Ciechan
  • 13,492
  • 11
  • 76
  • 118
0

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();
Tholle
  • 108,070
  • 19
  • 198
  • 189