升级到 Xamarin.iOS 9.8.0.323 后使用外部 IP 地址的 NameResolutionFailure

NameResolutionFailure with external IP address after upgrading to Xamarin.iOS 9.8.0.323

我的 Xamarin 应用在与后端 Web 服务通信时使用外部 IP 地址。用Xamarin.iOS9.6.2.4,调用成功。升级到 Xamarin.iOS 9.8.0.323 后,我现在遇到异常消息 "Error:NameResolutionFailure."

如果我切换到使用内部 IP 地址或 FQDN,则调用成功。

这似乎是最新的 Xamarin 更新中的错误,还是应该更改发出请求的方式?

try
{
  //Exception message - Error:NameResolutionFailure
  string url = "http://[External-IP-Address]:8081/MyWebService/api/GetByID/1";

  //The following two URLs are successful
  //string url = "http://[Internal-IP-Address]:8081/MyWebService/api/GetByID/1";
  //string url = "http://[Fully-Qualified-Domain-Name]:8081/MyWebService/api/GetByID/1";

  HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(url));
  request.ContentType = "application/json";
  request.Method = "GET";
  request.Timeout = 10 * 60 * 1000;

  using (WebResponse response = await request.GetResponseAsync())
  {
    using (StreamReader reader = new StreamReader(response.GetResponseStream()))
    {
      string jsonData = reader.ReadToEnd();
    }
  }
}
catch (Exception e)
{
  Console.WriteLine(e.Message);
}

异常堆栈跟踪

at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x0005e] in /Users/builder/data/lanes/3339/39ebb778/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/System/System.Net/HttpWebRequest.cs:1005 
at System.Threading.Tasks.TaskFactory`1[TResult].FromAsyncCoreLogic (IAsyncResult iar, System.Func`2 endFunction, System.Action`1 endAction, System.Threading.Tasks.Task`1 promise, Boolean requiresSynchronization) [0x00014] in /Users/builder/data/lanes/3339/39ebb778/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/threading/Tasks/FutureFactory.cs:550 
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3339/39ebb778/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /Users/builder/data/lanes/3339/39ebb778/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187 
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/3339/39ebb778/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/3339/39ebb778/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 
at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/3339/39ebb778/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:357 
at TestURL.ViewController+<ViewDidLoad>c__async0.MoveNext () [0x000b0] in /Users/Administrator/Projects/TestURL/TestURL/ViewController.cs:26 

附加信息:

经过一些研究,这是 Cycle 7 基线版本的一个已知问题。我们正在跟踪以下 public 错误:https://bugzilla.xamarin.com/show_bug.cgi?id=41782

此时,最好的选择是继续使用第 6 周期或(如果可能)使用完全限定的域名。

谢谢!