IndexOutOfRangeExeption Xamarin Live Player

时间:2018-03-19 13:38:02

标签: android xamarin visual-studio-2017 indexoutofboundsexception xamarin-live-player

I'm studying Xamarin for two weeks now and I'm following the Xamarin.University course (Consuming REST-based Web Services (XAM150)). In an exercise we have to simply check the connection of the phone. My emulator (Android 7.0) in Visual Studio 2017 does it very well. But when I try on my actual phone (Android 7.1) using Xamarin Live Player, the app will not start and the following Error appears on my phone:

"Visualization Error. Index was outside the bounds of the array. (IndexOutOfRangeExeption)"

I've searched Google and the forum of Xamarin.University but no luck, it seems that no one else has this problem. When I debug, it stops at when it checks the connectivity. I use the Xam.Plugin.Connectivity for asking the connection and yes, it is referenced in all the parts of the project. I've come from using this code from the site:

using Plugin.Connectivity;

public App() {
   // The root page of your application
   MainPage = CrossConnectivity.Current.IsConnected 
        ? (Page) new NetworkViewPage() 
        : new NoNetworkPage();
}

To this to debug:

using Plugin.Connectivity;
public App() {
    InitializeComponent();

    try {
        var isConnected = CrossConnectivity.Current.IsConnected;

        MainPage = isConnected
                   ? (Page)new NetworkViewPage()
                   : (Page)new NoNetworkPage();
    } catch (Exception e) {
        throw e;
    }
    //MainPage = new NetworkViewPage();
}

All this code works for my emulator, but not for my phone. I can display the different pages on my phone but not when I check for the connectivity so the error is really from the plugin and not from my pages.

Has someone any idea what I can try to make this work?

1 个答案:

答案 0 :(得分:0)

Frauke Nonnenmacher指出,这可能是 Xamarin Live Player的问题,并且显然是问题所在。如果我通过USB调试在手机上实现它,它可以正常工作。我发现Live Player可能是自Xamarin以来的问题并没有发生。大学希望你使用它,而我在论坛上找不到任何有同样问题的人。

我的猜测是检查连接会给Xamarin Live Player带来问题,因为它可以在网络上运行,如果你没有wifi连接就无法使用播放器。所以也许出现问题。 为什么它不起作用仍然是一个谜,但解决方法只是USB调试