gpt4 book ai didi

c# - 尝试读取异步 OAuth 请求响应时 System.Net.Http.Formatting.dll 中未处理的 FileNotFound 异常

转载 作者:可可西里 更新时间:2023-11-01 16:42:34 25 4
gpt4 key购买 nike

更新/理论我相信使用 Newtonsoft.json 4.5.0.0 版本可以更好地说明这个特定错误,该版本在他们的网站上似乎不存在:https://www.nuget.org/packages/Newtonsoft.Json/或者根本没有,真的 - 有没有其他人看到过这个?

原创

在请求 OAuth token (使用以下代码)后尝试读取响应时,我收到此错误:

An unhandled exception of type 'System.IO.FileNotFoundException' occurred in System.Net.Http.Formatting.dll

Additional information: Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=34etz678bn443' or one of its dependencies. The system cannot find the file specified.

代码:

HttpClient client = new HttpClient();
client.BaseAddress = new Uri(BaseURL + RequestOAuthTokenURL);

client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(
string.Format("{0}:{1}", Username, Password))));
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

string urlParameters = "";
HttpResponseMessage response = client.GetAsync(urlParameters).Result;
if (response.IsSuccessStatusCode)
{
var dataObjects = response.Content.ReadAsAsync<IEnumerable<DataObject>>().Result; //<-- offending line
foreach (var dataObj in dataObjects)
{
Console.WriteLine("{0}", dataObj.Name);
}
}

我读到这可能是由多种原因引起的(从错误的请求参数到依赖树中丢失的文件)。但是,我无法通过寻找任何建议的答案来找到问题的根源。此外,我的用户名和密码看起来没问题,不会导致 401(输入垃圾凭据会发生,并且不会发生此错误)。任何想法将不胜感激!

最佳答案

这解决了我的问题: http://www.tomasvoracek.com/2015/07/could-not-load-file-or-assembly-newtonsoft-json-version4-5-0-0-cultureneutral-publickeytoken30ad4fe6b2a6aeed-or-one-of-its-dependencies/我在 Tools/NuGet Package Manager/Package Console Manager 中执行了一个“get-package”,发现版本为 6.0.4,并将 bindingRedirect 版本设置为 6.0.0.0,这解决了问题。

关于c# - 尝试读取异步 OAuth 请求响应时 System.Net.Http.Formatting.dll 中未处理的 FileNotFound 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27733944/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com