Bug 57142 - Page creation fails with NRE with XamlC custom control
Summary: Page creation fails with NRE with XamlC custom control
Status: ASSIGNED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.3.4
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Stephane Delcroix
URL:
Depends on:
Blocks:
 
Reported: 2017-06-05 13:58 UTC by Philipp Sumi
Modified: 2017-06-07 13:24 UTC (History)
2 users (show)

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


Attachments
Tab control (5.25 KB, application/x-zip-compressed)
2017-06-05 13:59 UTC, Philipp Sumi
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 for Bug 57142 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
ASSIGNED

Description Philipp Sumi 2017-06-05 13:58:23 UTC
I have another issue where behavior with XamlC is different than without. I have two pages that contain a custom tab control. That control itself has XAML compilation enabled, and it works just fine. The control's XAML itself is also trivial:

<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:cv="clr-namespace:CarouselView.FormsPlugin.Abstractions;assembly=CarouselView.FormsPlugin.Abstractions"
             x:Class="Ridr.Client.Controls.Tabs">
    <ContentView.Content>
        <Grid x:Name="LayoutRoot"
              RowSpacing="0">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>

            <Grid x:Name="TabHeaderRoot"
                  BackgroundColor="{StaticResource Primary}"
                  RowSpacing="0"
                  ColumnSpacing="0"
                  Grid.Row="0" />

            <cv:CarouselViewControl x:Name="ContentCarousel"
                                    Position="{Binding SelectedIndex, Mode=TwoWay}"
                                    ItemsSource="{Binding TabItems}"
                                    ItemTemplate="{Binding ItemTemplate}"
                                    HorizontalOptions="FillAndExpand"
                                    VerticalOptions="FillAndExpand"
                                    BackgroundColor="{StaticResource WindowBackground}"
                                    Grid.Row="1" />
        </Grid>
    </ContentView.Content>
</ContentView>


So far so good, my app works fine. However, as soon as I enable XAML compilation on the *page* that contains the control, I'm ending up with a NullReferenceException during the page's InitializeComponent. Here's the page, stripped down to that control:


<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
             xmlns:controls="clr-namespace:Ridr.Client.Controls;assembly=Ridr.Client"
             prism:ViewModelLocator.AutowireViewModel="True"
             Title="{Binding Title}"
             x:Class="Ridr.Client.Views.CarpoolPage">

    <controls:Tabs/>

</ContentPage>



And here's the exception:

---> System.NullReferenceException: Object reference not set to an instance of an object
  at Ridr.Client.Views.CarpoolPage.InitializeComponent () [0x014ea] in <0487233c87bd41d0899a856cb26a227c>:0 
  at Ridr.Client.Views.CarpoolPage..ctor () [0x00008] in <0487233c87bd41d0899a856cb26a227c>:0 
  at (wrapper dynamic-method) System.Object:lambda_method (System.Runtime.CompilerServices.Closure,Microsoft.Practices.ObjectBuilder2.IBuilderContext)
  at Microsoft.Practices.ObjectBuilder2.DynamicBuildPlanGenerationContext+<>c__DisplayClass1.<GetBuildMethod>b__0 (Microsoft.Practices.ObjectBuilder2.IBuilderContext context) [0x00000] in <ba86a34b2f2c4964b8c588538e94514f>:0 
  at Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp (Microsoft.Practices.ObjectBuilder2.IBuilderContext context) [0x00000] in <ba86a34b2f2c4964b8c588538e94514f>:0 
  at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp (Microsoft.Practices.ObjectBuilder2.IBuilderContext context) [0x00064] in <ba86a34b2f2c4964b8c588538e94514f>:0 
  at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp (Microsoft.Practices.ObjectBuilder2.IBuilderContext context) [0x0007c] in <ba86a34b2f2c4964b8c588538e94514f>:0 
  at Microsoft.Practices.Unity.UnityContainer.DoBuildUp (System.Type t, System.Object existing, System.String name, System.Collections.Generic.IEnumerable`1[T] resolverOverrides) [0x00068] in <ba86a34b2f2c4964b8c588538e94514f>:0 
   --- End of inner exception stack trace ---
  at Microsoft.Practices.Unity.UnityContainer.DoBuildUp (System.Type t, System.Object existing, System.String name, System.Collections.Generic.IEnumerable`1[T] resolverOverrides) [0x0007b] in <ba86a34b2f2c4964b8c588538e94514f>:0 
  at Microsoft.Practices.Unity.UnityContainer.DoBuildUp (System.Type t, System.String name, System.Collections.Generic.IEnumerable`1[T] resolverOverrides) [0x00000] in <ba86a34b2f2c4964b8c588538e94514f>:0 
  at Microsoft.Practices.Unity.UnityContainer.Resolve (System.Type t, System.String name, Microsoft.Practices.Unity.ResolverOverride[] resolverOverrides) [0x00000] in <ba86a34b2f2c4964b8c588538e94514f>:0 
  at Microsoft.Practices.Unity.UnityContainerExtensions.Resolve[T] (Microsoft.Practices.Unity.IUnityContainer container, System.String name, Microsoft.Practices.Unity.ResolverOverride[] overrides) [0x0000b] in <ba86a34b2f2c4964b8c588538e94514f>:0 
  at Prism.Unity.Navigation.UnityPageNavigationService.CreatePage (System.String name) [0x00000] in <d48531d8cf994cb8b9baff9564ac22d2>:0 
  at Prism.Navigation.PageNavigationService.CreatePageFromSegment (System.String segment) [0x00052] in <7a32c28f35024e719a93e31b4d1e3d2a>:0 
  at Prism.Navigation.PageNavigationService+<ProcessNavigationForContentPage>d__17.MoveNext () [0x00063] in <7a32c28f35024e719a93e31b4d1e3d2a>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <3fd174ff54b146228c505f23cf75ce71>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <3fd174ff54b146228c505f23cf75ce71>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <3fd174ff54b146228c505f23cf75ce71>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <3fd174ff54b146228c505f23cf75ce71>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <3fd174ff54b146228c505f23cf75ce71>:0 
  at Prism.Navigation.PageNavigationService+<ProcessNavigation>d__14.MoveNext () [0x0016b] in <7a32c28f35024e719a93e31b4d1e3d2a>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <3fd174ff54b146228c505f23cf75ce71>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <3fd174ff54b146228c505f23cf75ce71>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <3fd174ff54b146228c505f23cf75ce71>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <3fd174ff54b146228c505f23cf75ce71>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <3fd174ff54b146228c505f23cf75ce71>:0 
  at Ridr.Client.Views.Fragments.Home.HomepageRideModel+<GoToRide>d__26.MoveNext () [0x00182] in <0487233c87bd41d0899a856cb26a227c>:0 



I know that's not much to work with. I can live without Xaml compilation for the pages that use that control, but the fact that this fails with a nondescript crash it makes me somewhat uneasy, since I don't know the implications for other controls/pages and/or platforms.
Comment 1 Philipp Sumi 2017-06-05 13:59:45 UTC
Created attachment 22699 [details]
Tab control
Comment 2 Philipp Sumi 2017-06-05 14:10:07 UTC
Please ignore until I post here again. I caused another NRE while removing stuff, need to make sure I'm not putting any red herrings into the bug report.
Comment 3 Philipp Sumi 2017-06-05 14:50:46 UTC
Ok, the stripped down page caused an NRE by itself due to a missing ItemsSource. Should have been this:

<controls:Tabs>
  <controls:TabModelCollection />
</controls:Tabs>


Fixing this gets me back to the originally reported NRE (so the problem is still the same).