c# - HttpClientHandler :Dispose (bool )' is inaccessible from method ` System.Net.ServicePointManager:CloseConnectionGroup(字符串)

标签 c# xamarin xamarin.forms

"HttpClientHandler:Dispose (bool)' is inaccessible from method `System.Net.ServicePointManager:CloseConnectionGroup (string)"

发送请求时出现这个错误,如何解决?

using (var client = new HttpClient())
{
  client.BaseAddress = new Uri(urlTemplate);
  client.Timeout = new TimeSpan(0, 0, 30);
  var connectionString = string.Format(UrlTemplate, method.ToString().ToLower(), CreateParametrsString(parametrs));
  var response = await client.GetAsync(connectionString);
  if (response.StatusCode != HttpStatusCode.OK)
   {
     using (StreamReader reader = new StreamReader((await response.Content.ReadAsStreamAsync()), Encoding.GetEncoding("windows-1252")))
      {
        content = reader.ReadToEnd();
        var json = content;
        var ass = JsonConvert.DeserializeObject<T>(json);
        if (ass != null)
          Debug.WriteLine(String.Format("=>GETTED [{0}] table.", typename));
        else
          LoggingService.Report(null, new Dictionary<string, string> {
             { "request",typename },
             { "content",content },
             });
          return ass;
        }
    }
 }

最佳答案

您很可能遇到了 mono 框架中的错误。我相信是

https://bugzilla.xamarin.com/show_bug.cgi?id=41133

有两个拉取请求可以解决此问题:

https://github.com/mono/mono/pull/4277 (主修复)

https://github.com/mono/mono/pull/4278 (单声道 4.8 中的 Cycle9 修复)

包含此修复的当前 Mono 版本是:

https://github.com/mono/mono/releases/tag/mono-4.8.0.478

因此您需要一个包含此版本或更高版本的构建。

https://github.com/mono/mono/commits/084f91256b05249f5f35973019561e6fefbdc053/mono/utils/mono-sha1.c

因此这应该包含在当前的 Beta channel 构建中:

https://releases.xamarin.com/beta-release-cycle-9-rc-refresh-builds3/

关于c# - HttpClientHandler :Dispose (bool )' is inaccessible from method ` System.Net.ServicePointManager:CloseConnectionGroup(字符串),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42018890/

相关文章:

ios - Xamarin.iOS 相当于 Xamarin.Android 的 CookieManager.Instance

xamarin.forms - ContentView发生变化时如何动态改变导航栏标题?

android - Xamarin 表单 |安卓 : BitmapDescriptor Error - Image must be a Bitmap

c# - 如何使用 async/await 实现命令模式

c# - Sitecore 插入选项是否可以根据父项有条件地添加模板?

c# - 如何伪造 EntityFramework.Extended FutureQuery?

c# - 处理您的请求时发生错误。请求 ID : 0HLEALBF2I2PS:00000007

Xamarin 表单水平 ListView ,带有用于将日期向右、向左移动的按钮

c# - 我可以使用 NSUrlSession 在 HTTP header 中允许原始 unicode 吗?

android - 使用 Visual Studio 从 Xamarin 中的 Activity 获取对象结果