【问题标题】:Visual Studio Xamarin Android System.Net.WebException: Error: ConnectFailure (Network is unreachable)Visual Studio Xamarin Android System.Net.WebException:错误:ConnectFailure(网络无法访问)
【发布时间】:2018-03-20 16:33:28
【问题描述】:

我在 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

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

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

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

【问题讨论】:

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


    【解决方案1】:

    据我了解,您的 Android 应用程序未授予 Internet 权限,或者您没有 Internet 连接,以防您没有权限,您只需在清单中添加此行.

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

    【讨论】:

    • 在创建此主题之前,我检查了其他主题和教程,因此我的 android 清单文件中有这句话。同样奇怪的是,有时会出现这个问题,有时一切都很好。我将 System.Net.HTML 添加到引用中,因此在最后几次测试中没有出现问题。
    猜你喜欢
    • 1970-01-01
    • 2020-08-17
    • 2018-02-07
    • 1970-01-01
    • 1970-01-01
    • 2018-01-09
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多