c# - System.AccessViolationException 发生在 System.Net.Http C#
问题描述
我有以下代码:
using (var ct = new Google.Apis.SearchConsole.v1.SearchConsoleService(new BaseClientService.Initializer
{
ApiKey = ConfigurationManager.AppSettings["googleSearchApiKey"],
ApplicationName = "my info"
}))
{
html = ct.HttpClient.GetStringAsync("https://www.google.com/search?q=" + WebUtility.UrlEncode(gameName) + "+origin+pc+game").Result;
}
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(html);
var glist = doc.DocumentNode.GetById("search")?.GetByClass("g");
if (glist != null)
{
var off = glist.First();
var a = off.GetByTag("a").FirstOrDefault();
if (a != null)
{
var url = a.GetAttributeValue("href", "");
if (!string.IsNullOrWhiteSpace(url))
{
url = WebUtility.UrlDecode(url);
url = url.Substring(url.IndexOf("?q=") + 3);
url = url.Substring(0, url.IndexOf('&'));
gameUrl = url;
return stuff;
}
}
}
到达时ct.HttpClient.GetStringAsync
,我得到了漂亮的错误页面:
应用程序:MyApp.exe 框架版本:v4.0.30319 描述:进程因未处理的异常而终止。异常信息: System.Net.Http.HttpClient.SendAsync 处的 System.AccessViolationException(System.Net.Http.HttpRequestMessage,System.Net.Http.HttpCompletionOption,System.Threading.CancellationToken)处 System.Net.Http.HttpClient.GetAsync( System.Uri、System.Net.Http.HttpCompletionOption、System.Threading.CancellationToken)
为什么 ?
解决方案
推荐阅读
- java - Android RecyclerView:在 RecyclerView 中的卡片之间滑动
- file - 如何将正则表达式与 ansible 文件模块一起使用
- python - 如何在 Kivy 中更改颜色
- c# - 纸牌游戏在一段时间内递增(c#)
- reactjs - OnsenUI Navigator + React 导航失败
- android - FAILURE:构建失败并出现异常。任务“:app:mergeDebugResources”执行失败
- jquery - 如何增加颜色的亮度 jQuery
- c++ - 如何从文件中读取并将字符串输入到vars?
- mongodb - 将对象数组中的 int 数组字段连接到 mongodb 聚合中的一个字符串字段中
- vba - 如何在 MS-Access 表单中预选 ListBox 中的值?