问题描述
我一直在使用Xamarin和MvvmCross开发适用于Android的应用程序,一切都进行得很好,我和我的团队得以开发该解决方案,本周我们决定进行最终调整,并在其他版本中测试该应用程序环境.在测试期间,我在使用Android解决方案时遇到了很大的问题.在工作环境中,一切正常,但是当我尝试在家中测试应用程序时,该应用程序停止了工作.我检查了情况,发现HttpClient无法完成对服务器的调用并引发以下异常:
I've been developing an application for Android using Xamarin with MvvmCross and everything has been going fine, me and my team were able to develop the solution and this week we decided to make the final adjustments and to test the application in other environments.During the tests I had a huge problem with the Android solution. In the working environment everything was working fine but when I tried to test the application at home the application stopped working. I checked what was happening and I found out that the HttpClient was not being able to complete a call to the server and throwing the following exception:
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter`1[System.Net.Http.HttpResponseMessage].GetResult () [0x00000] in <filename unknown>:0
at System.Net.Http.HttpClientHandler+<SendAsync>c__async0.MoveNext () [0x00000] in <filename unknown>:0
我在Google中搜索了一个解决方案,并且在Xamarin论坛中发现了类似的问题 http ://forums.xamarin.com/discussion/30152/error-nameresolutionfailure (Jefimijana帖子),答案之一是关于网络配置错误,这对我来说似乎很奇怪,因为所有其他应用程序都可以正常工作.我测试了连接到同一wifi的WPF应用程序,以检查是否有任何问题,但工作正常.因此,我发现自己遇到了一个更大的问题,当所有其他应用程序正常工作时,我无法告诉用户他必须重新调整其wifi连接,并且我也无法让我的应用程序出于某些明显原因而无法与某些wifis配合使用.所以我的问题是,这个问题有解决方案吗?这是与HttpClient相关的某种Xamarin问题吗?还是这是Android问题?
I searched for a solution in Google and I found a similar problem in the Xamarin Forum http://forums.xamarin.com/discussion/30152/error-nameresolutionfailure (Jefimijana post) and one of the answers was about network misconfiguration wich seems odd to me because all other applications seem to work just fine.I tested the WPF application connected to the same wifi to check if there was any problem but it worked just fine.So there I found myself with an even bigger problem, I cannot tell the user that he has to readjust his wifi connection when all other applications work properly and I cannot have my application not working with some wifis for no apparent reason.So my question is, is there a solution for this problem? Is this some sort of Xamarin problem related to the HttpClient? Or is this an Android problem?
- 我一直在测试的设备是Samsung Galaxy Tab 3
谢谢
推荐答案
不幸的是,您尚未提供有关尝试操作的更多信息,但我可以确认我们在Xamarin.Android中看到了类似的错误行为.应用.
Unfortunately, you haven't provided more information about what you are trying to do, but I can confirm that we are seeing similar buggy behavior in our Xamarin.Android Apps.
Android上的Mono Network Stack至少有两个问题(截至2015年2月),因此您并不孤单:
The Mono Network Stack on Android has at least two problems (as of Feb 2015) that we are experiencing, so you are not alone:
- 在应用程序发出的前几个http请求中,偶尔出现
-
NameResolutionFailure
.该问题通常会消失,我们已经确认这不是网络配置问题(例如,浏览器/WebView发出的所有请求都可以正常进行).其他人报告了类似的问题: https://bugzilla.xamarin.com/show_bug.cgi?id=18613 - SSL连接不可靠,请参见 https://bugzilla.xamarin.com/show_bug.cgi?id=19334
- Occasional
NameResolutionFailure
on the first few http requests issued by the App. The issue usually goes away and we have confirmed it's not a network configuration issue (e.g. all requests made by a browser / WebView go through fine). Others have reported similar issues: https://bugzilla.xamarin.com/show_bug.cgi?id=18613 - SSL connections are unreliable, see https://bugzilla.xamarin.com/show_bug.cgi?id=19334
目前我可以推荐给您的最佳解决方法是使用 ModernHttpClient ,它是使用本机API,因此不涉及单声道网络堆栈(而且它的速度也要快得多).
The best workaround I can recommend to you at the moment is to use ModernHttpClient, which is a HttpClientHandler
implementation that uses a native API and thus doesn't involve the mono Network stack (plus it's considerably faster too).
这篇关于HttpClient-Xamarin Android-MvvmCross的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!