Bug 56946 - All Xamarin.Forms UWP apps are crashing with System.ArgumentException on Forms.Init
Summary: All Xamarin.Forms UWP apps are crashing with System.ArgumentException on Form...
Status: RESOLVED ANSWERED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: unspecified
Hardware: PC Windows
: --- critical
Target Milestone: ---
Assignee: Paul DiPietro [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2017-05-29 19:23 UTC by Mihai Pirvu
Modified: 2017-06-21 04:00 UTC (History)
5 users (show)

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

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 or GitHub 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 Mihai Pirvu 2017-05-29 19:23:27 UTC
This started happening about two weeks ago. No UWP app is working anymore, new or old. The projects work fine on other machines. The issue might be related to the fact that I am currently on an Insider Build (16199). My guess is that some UWP API has changed and is causing this, however I do not know whether this issue is because the UWP API is broken in this Insider Build, or because it is an unforseen bug inside XF.

# Steps to reproduce
* Open VS 2017
* New Project -> Cross Platform App (Xamarin.Forms or Native)
* Choose "Blank App", "Xamarin.Forms" and "Portable Class Library (PCL)"
* Choose UWP settings (although I have tried different settings as well, all the way to 10240/10240, still no change)
    * Target version : 15063 (creators update)
    * Minimum version : 10586 (november update)
* Set UWP project as startup
* Configure Build + Deploy for UWP project for the current build configuration
* Debug

# Expected behavior
* App should work

# Actual behavior
Xamarin.Forms.Forms.Init(e); throws :
System.ArgumentException: 'Value does not fall within the expected range.'
   at Windows.Storage.StorageFolder.CreateFileQueryWithOptions(QueryOptions queryOptions)
   at Xamarin.Forms.Platform.UWP.WindowsBasePlatformServices.GetAssemblies()
   at Xamarin.Forms.Registrar.RegisterAll(Type[] attrTypes)
   at Xamarin.Forms.Forms.Init(IActivatedEventArgs launchActivatedEventArgs, IEnumerable`1 rendererAssemblies)
   at test.UWP.App.OnLaunched(LaunchActivatedEventArgs e)

# Supplemental info (logs, images, videos)
The issue seems to be coming from this file, line 56 :
https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Platform.WinRT/WindowsBasePlatformServices.cs

# Test environment (full version information)
Windows 10 Insiders Build 16199
VIsual Studio 2017 15.2 (26430.6) Release
Xamarin 4.5.0.443
Xamarin.Forms 2.3.4.224 (this seems to be unrelated, I checked some older versions as well)

Please let me know if you need any further info related to my environment or anything else.
Thank you!
Comment 1 Paul DiPietro [MSFT] 2017-06-01 17:09:38 UTC
I have the 16199 build installed and am not experiencing this following those steps. I can't say if it's an XF-specific issue for the time being. but will leave this open under needinfo in case anyone else experiences this, or if you find a reliable path to reproduction.
Comment 2 jlewis 2017-06-14 07:58:56 UTC
I'm having a similar problem. 

Xamarin.Forms v 2.3.4.247

My XAML is simple: 

<?xml version="1.0" encoding="UTF-8"?>
<ContentView 
    xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
    xmlns:dxc="clr-namespace:DoggoX.Controls"
    xmlns:dxv="clr-namespace:DoggoX.Views"
    xmlns:dxvm ="clr-namespace:DoggoX.ViewModels"
    xmlns:dxh ="clr-namespace:DoggoX.Helpers"
    x:Class="DoggoX.Views.ConFrontPageView">

    <ContentView.BindingContext>
        <dxvm:ConFrontPageVM x:Name="VM"/>
    </ContentView.BindingContext>

    <ContentView.Resources>
        <ResourceDictionary>
            <dxh:ScaleConverter x:Key="Scaler" />
        </ResourceDictionary>
    </ContentView.Resources>
    
    <ContentView.Content>

        <Grid x:Name="grdFrame">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
                <Button Text="Load" Clicked="Button_Clicked" Grid.Column="2"/>
            </Grid.ColumnDefinitions>
        </Grid>

        <!-- <dxv:ConMainMenuView /> -->
    </ContentView.Content>
</ContentView>

And it compiles.. but on execution, the constructor:

    public partial class ConFrontPageView : global::Xamarin.Forms.ContentView {
        
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Forms.Build.Tasks.XamlG", "0.0.0.0")]
        private global::DoggoX.ViewModels.ConFrontPageVM VM;
        
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Forms.Build.Tasks.XamlG", "0.0.0.0")]
        private global::Xamarin.Forms.Grid grdFrame;
        
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Forms.Build.Tasks.XamlG", "0.0.0.0")]
        private void InitializeComponent() {
            global::Xamarin.Forms.Xaml.Extensions.LoadFromXaml(this, typeof(ConFrontPageView));
            VM = global::Xamarin.Forms.NameScopeExtensions.FindByName<global::DoggoX.ViewModels.ConFrontPageVM>(this, "VM");
            grdFrame = global::Xamarin.Forms.NameScopeExtensions.FindByName<global::Xamarin.Forms.Grid>(this, "grdFrame");
        }

throws this exception:

System.ArrayTypeMismatchException occurred
  HResult=0x80131503
  Message=Attempted to access an element as a type incompatible with the array.
  Source=<Cannot evaluate the exception source>
  StackTrace:
   at System.Collections.Generic.List`1.Add(T item)
   at Xamarin.Forms.DefinitionCollection`1.Add(T item)
   at DoggoX.Views.ConFrontPageView.InitializeComponent() in C:\Users\werewolf\Source\Workspaces\Furry Migration App\DoggoX-Main\DoggoX\DoggoX.UWP\obj\x64\Debug\DoggoX.UWP.C_.Users.werewolf.Source.Workspaces.Furry_Migration_App.DoggoX_Main.DoggoX.DoggoX.Views.ConFrontPageView.xaml.g.cs:line 29
   at DoggoX.Views.ConFrontPageView..ctor() in C:\Users\werewolf\Source\Workspaces\Furry Migration App\DoggoX-Main\DoggoX\DoggoX\Views\ConFrontPageView.xaml.cs:line 12
   at DoggoX.Pages.ConFrontPage.InitializeComponent() in C:\Users\werewolf\Source\Workspaces\Furry Migration App\DoggoX-Main\DoggoX\DoggoX.UWP\obj\x64\Debug\DoggoX.UWP.C_.Users.werewolf.Source.Workspaces.Furry_Migration_App.DoggoX_Main.DoggoX.DoggoX.Pages.ConFrontPage.xaml.g.cs:line 25
   at DoggoX.Pages.ConFrontPage..ctor() in C:\Users\werewolf\Source\Workspaces\Furry Migration App\DoggoX-Main\DoggoX\DoggoX\Pages\ConFrontPage.xaml.cs:line 16
   at DoggoX.App.SetMainPage() in C:\Users\werewolf\Source\Workspaces\Furry Migration App\DoggoX-Main\DoggoX\DoggoX\App.xaml.cs:line 46
   at DoggoX.App..ctor() in C:\Users\werewolf\Source\Workspaces\Furry Migration App\DoggoX-Main\DoggoX\DoggoX\App.xaml.cs:line 24
   at DoggoX.UWP.MainPage..ctor() in C:\Users\werewolf\Source\Workspaces\Furry Migration App\DoggoX-Main\DoggoX\DoggoX.UWP\MainPage.xaml.cs:line 9
   at DoggoX.UWP.DoggoX_UWP_XamlTypeInfo.XamlTypeInfoProvider.Activate_4_MainPage() in C:\Users\werewolf\Source\Workspaces\Furry Migration App\DoggoX-Main\DoggoX\DoggoX.UWP\obj\x64\Debug\XamlTypeInfo.g.cs:line 207
   at DoggoX.UWP.DoggoX_UWP_XamlTypeInfo.XamlUserType.ActivateInstance() in C:\Users\werewolf\Source\Workspaces\Furry Migration App\DoggoX-Main\DoggoX\DoggoX.UWP\obj\x64\Debug\XamlTypeInfo.g.cs:line 427


So in the above, the "grdFrame" lookup is throwing the exception. If I remove the name from the last one, the one before it will throw the exception.
Comment 3 Rui Marinho 2017-06-20 17:18:00 UTC
You are inserting the button inside the Grid.ColumnDefinitions, you should add the button after </Grid.ColumnDefinitions>
Comment 4 jlewis 2017-06-21 04:00:31 UTC
Gah.. you're right.. I completely missed that.

But.. why would it cause that specific exception? 

In WPF, that is marked as an exception in the XAML editor... and at compile time, it's flagged as being the wrong type in a ColumnDefinitions list.

I should also note that if you're viewing the XAML editor (for Xamarin.Forms) in UWP mode, it doesn't seem to be able to find the namespaces for Xamarin.Forms and basically marks everything as invalid. Switching to Android or iOS fixes that, but that introduces other issues if you have platform specific code.