Xamarin.forms: Populating a CollectionView with data error with System.TypeInitializationException: The type initializer for 'Xamarin.Forms.ItemsView' threw an exception.

Created on 21 Mar 2019  路  1Comment  路  Source: xamarin/Xamarin.Forms

https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/collectionview#populating-a-collectionview-with-data

Description

When I add the Xaml code of CollectionView to my project, I find that it can't run, and I will report the following _error: System.TypeInitializationException: The type initializer for 'Xamarin.Forms.ItemsView' threw an exception._

Steps to Reproduce

  1. Create a new forms app, update xamarin forms to Xamarin.Forms 4.0-pre7
  2. Add code in Xaml:
 <StackLayout>
        <!-- Place new controls here -->
        <Label Text="Welcome to Xamarin.Forms!" 
           HorizontalOptions="Center"
           VerticalOptions="CenterAndExpand" />
        <CollectionView>
            <CollectionView.ItemsSource>
                <x:Array Type="{x:Type x:String}">
                    <x:String>Baboon</x:String>
                    <x:String>Capuchin Monkey</x:String>
                    <x:String>Blue Monkey</x:String>
                    <x:String>Squirrel Monkey</x:String>
                    <x:String>Golden Lion Tamarin</x:String>
                    <x:String>Howler Monkey</x:String>
                    <x:String>Japanese Macaque</x:String>
                </x:Array>
            </CollectionView.ItemsSource>
        </CollectionView>
    </StackLayout>
  1. Run project ,then happen this error:

System.TypeInitializationException: The type initializer for 'Xamarin.Forms.ItemsView' threw an exception.

Expected Behavior

Actual Behavior

Basic Information

  • Version with issue:
  • Last known good version:
  • IDE: VS-2017-15.9.8
  • Platform Target Frameworks:

    • iOS: IOS 12.1

    • Android: Android 8.1

  • Android Support Library Version: API 27
  • Nuget Packages:Xamarin.Forms 4.0-pre7
  • Affected Devices: IPhoneX / AndroidEmulator

Screenshots

image

Reproduction Link

https://www.dropbox.com/s/6ocl8e3g4azluxw/AppForms3.rar?dl=0

VS bug #824637

Most helpful comment

Please add Forms.SetFlags("CollectionView_Experimental"); to your AppDelegate and MainActivity, as described in the paragraph above section you linked to in the documentation. Thanks!

>All comments

Please add Forms.SetFlags("CollectionView_Experimental"); to your AppDelegate and MainActivity, as described in the paragraph above section you linked to in the documentation. Thanks!

Was this page helpful?
0 / 5 - 0 ratings