Bug 53926 - ListView inside StackLayout causes Forms Previewer to throw a "you MUST call Xamarin.Forms.Init" exception.
Summary: ListView inside StackLayout causes Forms Previewer to throw a "you MUST call ...
Status: RESOLVED ANSWERED
Alias: None
Product: Visual Studio Extensions
Classification: Xamarin
Component: Xamarin.Forms Previewer ()
Version: 4.3.0 (C9)
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-03-24 16:22 UTC by Heinrich Moser
Modified: 2017-03-27 09:20 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Stacktrace screenshot (39.59 KB, image/png)
2017-03-24 16:22 UTC, Heinrich Moser
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Description Heinrich Moser 2017-03-24 16:22:39 UTC
Created attachment 20815 [details]
Stacktrace screenshot

Repro
=====

1. Create a default C# Xamarin Forms project in Visual Studio 2017.

2. Replace the main page with the following XAML code (replace MyProject with your root namespace):

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MyProject.MainPage">

    <StackLayout>
        <ListView ItemsSource="{Binding Items}">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <Label Text="{Binding Text}" />
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackLayout>
</ContentPage>

3. Compile and open the Forms Previewer.

Expected result
===============

An empty list is shown.

Actual result
=============

The forms previewer shows a System.InvalidOperationException with the message "You MUST call Xamarin.Forms.Init() prior to using it.". The stack trace can be found in the screen shot (sorry about that, but I did not find a way to copy&paste the data).
Comment 1 Alan McGovern 2017-03-24 17:37:22 UTC
This should be fixed if you upgrade to Xamarin.Forms 2.3.4 pre5 or newer, which is currently on Nuget. If you have issues after updating to that then please reopen the bug and we'll investigate further!
Comment 2 Heinrich Moser 2017-03-27 08:50:43 UTC
Thanks, upgrading to the latest preview version fixed the issue.

Preview now fails when a SearchBar is included with "java.lang.UnsupportedOperationException: Unsupported Service: class android.view.inputmethod.InputMethodManager".

Should I open a new bug for this or are you already aware of the issue? (I found this Android issue raised by one of your people, so I suspect the latter: <https://code.google.com/p/android/issues/detail?id=231975>.)
Comment 3 Alan McGovern 2017-03-27 09:17:46 UTC
Yes, that is the bug we filed upstream. Hopefully it gets fixed/released soon!

Also, we did add a workaround in Xamarin.Forms itself for this particular issue, but it does not seem to have been included in 2.3.4. I'll see if it can be included in a future 2.3.4 preview, or simply the next release.
Comment 4 Heinrich Moser 2017-03-27 09:20:06 UTC
Great, thanks.