Visual Studio Xamarin Android System.Net.WebException:错误:ConnectFailure(网络无法访问)

时间:2017-10-09 12:48:26

标签: xamarin.android android-emulator visual-studio-2017 system.net.webexception

我在Xamarin中创建的Android应用程序遇到网络连接问题,下面是错误代码。

Time Device Name Type PID Tag Message 10-09 05:04:52.256 Genymotion Samsung Galaxy S7 - 6.0.0 - API 23 - 1440x2560 Error 1453 AndroidRuntime android.runtime.JavaProxyThrowable: System.Net.WebException: Error: ConnectFailure (Network is unreachable) ---> System.Net.Sockets.SocketException: Network is unreachable at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x000b6] in <6c708cf596db438ebfc6b7e012659eee>:0 at System.Net.WebConnection.Connect (System.Net.HttpWebRequest request) [0x0016d] in <6c708cf596db438ebfc6b7e012659eee>:0 --- End of inner exception stack trace --- at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke (System.String method_name, System.Object[] parameters) [0x000a7] in <3f9824dbe67544e1805773e0a3dbdf6b>:0 at GWAWE.localhost.Service1.Get_Data () [0x00001] in <1baad81b40d64c6886bf076df034661f>:0 at (wrapper remoting-invoke-with-check) GWAWE.localhost.Service1:Get_Data () at gwawe.MainActivity.BuildLayout () [0x00031] in <1baad81b40d64c6886bf076df034661f>:0 at gwawe.MainActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x0004e] in <1baad81b40d64c6886bf076df034661f>:0 at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x0000f] in <9663139ab15947a89e15a6bcd9621f68>:0 at (wrapper dynamic-method) System.Object:e6ea694d-cf84-4098-a161-481a5ad1d4ae (intptr,intptr,intptr) at md5a9dcb246785c0066d52ff25b77e1a72d.MainActivity.n_onCreate(Native Method) at md5a9dcb246785c0066d52ff25b77e1a72d.MainActivity.onCreate(MainActivity.java:29) at android.app.Activity.performCreate(Activity.java:6237) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Force finishing activity GWAWE.gwawe/md5a9dcb246785c0066d52ff25b77e1a72d.MainActivity

我正在使用Visual Studio 2017与Xamarin和Genymotion。 Visual Studio,Xamarin和Genymotion是最新的。应用程序仅针对Android 6.0创建。 在android manifest中我添加了android.permission.RECEIVE_BOOT_COMPLETED。 我在模拟器上使用“Wi-Fi”。

应用程序必须在设备启动后自动启动,并且只有在我重新启动模拟器时才显示错误。如果我手动运行应用程序一切正常。 该应用程序连接到IIS Web服务。

有没有人知道这里发生了什么?

1 个答案:

答案 0 :(得分:0)

根据我的理解,您的Android应用程序未授予互联网许可,或者您没有互联网连接,如果您没有权限,您只需在清单中添加此行

  <uses-permission android:name="android.permission.INTERNET" />