Bug 40872 - XAML x:Type Null Reference Exception in DataTemplate
Summary: XAML x:Type Null Reference Exception in DataTemplate
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: iOS ()
Version: 2.2.0
Hardware: PC Mac OS
: Normal major
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-05-04 18:31 UTC by John Miller [MSFT]
Modified: 2017-01-18 09:22 UTC (History)
3 users (show)

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


Attachments
Sample Project (53.36 KB, application/zip)
2016-05-04 18:31 UTC, John Miller [MSFT]
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 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 FIXED

Description John Miller [MSFT] 2016-05-04 18:31:05 UTC
Created attachment 15909 [details]
Sample Project

**Overview:**

   When trying to use x:Type in a DataTrigger of a DataTemplate (ListView) a NRE is thrown at runtime. 

**Steps to Reproduce:**

   1. Run the attached sample on an iOS or Android simulator.

**Actual Results:**

System.NullReferenceException: Object reference not set to an instance of an object
  at Xamarin.Forms.Xaml.Internals.XamlTypeResolver.Resolve (System.String qualifiedTypeName, System.IServiceProvider serviceProvider, Xamarin.Forms.Xaml.XamlParseException& exception) [0x00003] in <filename unknown>:0 
  at Xamarin.Forms.Xaml.Internals.XamlTypeResolver.Xamarin.Forms.Xaml.IXamlTypeResolver.Resolve (System.String qualifiedTypeName, System.IServiceProvider serviceProvider) [0x00000] in <filename unknown>:0 
  at Xamarin.Forms.Xaml.TypeExtension.ProvideValue (System.IServiceProvider serviceProvider) [0x00037] in <filename unknown>:0 
  at Xamarin.Forms.Xaml.CreateValuesVisitor.Visit (Xamarin.Forms.Xaml.ElementNode node, Xamarin.Forms.Xaml.INode parentNode) [0x0031e] in <filename unknown>:0 
  at Xamarin.Forms.Xaml.ElementNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode) [0x000b1] in <filename unknown>:0 
  at Xamarin.Forms.Xaml.ElementNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode) [0x00054] in <filename unknown>:0 
  at Xamarin.Forms.Xaml.ElementNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode) [0x00054] in <filename unknown>:0 
  at Xamarin.Forms.Xaml.ElementNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode) [0x00089] in <filename unknown>:0 
  at Xamarin.Forms.Xaml.ElementNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode) [0x00089] in <filename unknown>:0 
  at Xamarin.Forms.Xaml.ApplyPropertiesVisitor+<>c__DisplayClass26_0.<SetTemplate>b__0 () [0x0005d] in <filename unknown>:0 
  at Xamarin.Forms.ElementTemplate.CreateContent () [0x0002c] in <filename unknown>:0 
  at Xamarin.Forms.DataTemplateExtensions.CreateContent (Xamarin.Forms.DataTemplate self, System.Object item, Xamarin.Forms.BindableObject container) [0x00014] in <filename unknown>:0 
  at Xamarin.Forms.TemplatedItemsList`2[TView,TItem].CreateContent (System.Int32 index, System.Object item, System.Boolean insert) [0x00021] in <filename unknown>:0 
  at Xamarin.Forms.TemplatedItemsList`2[TView,TItem].GetOrCreateContent (System.Int32 index, System.Object item) [0x00023] in <filename unknown>:0 
  at Xamarin.Forms.TemplatedItemsList`2[TView,TItem].get_Item (System.Int32 index) [0x0000e] in <filename unknown>:0 
  at Xamarin.Forms.Platform.iOS.ListViewRenderer+ListViewDataSource.GetCellForPath (Foundation.NSIndexPath indexPath) [0x00032] in <filename unknown>:0 
  at Xamarin.Forms.Platform.iOS.ListViewRenderer+ListViewDataSource.GetCell (UIKit.UITableView tableView, Foundation.NSIndexPath indexPath) [0x00057] in <filename unknown>:0 
  at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Users/builder/data/lanes/1381/3afb4af5/source/maccore/src/UIKit/UIApplication.cs:79 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/1381/3afb4af5/source/maccore/src/UIKit/UIApplication.cs:63 
  at XTypeTest.iOS.Application.Main (System.String[] args) [0x00008] in /Users/johnmiller/Projects/XTypeTest/iOS/Main.cs:17 

**Expected Results:**

   No Exceptions.

**Build Date & Platform:**

   XF 2.2

**Additional Information:**

The issue is in MyPage.xaml line 17:

<DataTrigger TargetType="{x:Type Label}" Binding="{Binding IsCorrect}" Value="True">

If changed to this, it works OK:

<DataTrigger TargetType="Label" Binding="{Binding IsCorrect}" Value="True">
Comment 1 Stephane Delcroix 2017-01-18 09:22:12 UTC
unable to repro this in 2.3.3.180 with or without XamlC on