[英]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.