Bug 60349 - Specifying DataType on DataTemplate where the Poco has a generic property fails to compile
Summary: Specifying DataType on DataTemplate where the Poco has a generic property fai...
Status: CONFIRMED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.4.0
Hardware: PC Windows
: Normal major
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-10-24 15:05 UTC by Paul Kiar
Modified: 2017-11-14 00:06 UTC (History)
4 users (show)

Tags: datatemplate, datatype, generic, ac
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 for Bug 60349 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:
CONFIRMED

Description Paul Kiar 2017-10-24 15:05:00 UTC
To Reproduce:
Create a xamarin forms project as defined in this forum post:

https://blog.xamarin.com/databinding-power-moves-you-may-not-be-using-yet/

edit the Deal model object and add a property:

public bool? Test {get;set;}



Try to compile and you get this error:

Xamarin.Forms.2.4.0.282\build\portable-win+net45+wp80+win81+wpa81\Xamarin.Forms.targets(73,3): error : Member 'System.Nullable`1' is declared in another module and needs to be imported

Also fails if it has a property on the poco of Tuple<bool,bool> which leads me to believe it's a problem with generics.
Comment 1 Paul Kiar 2017-10-24 15:09:39 UTC
You may have to add a binding to this property to the DealControl

<Label Text="{Binding Test}" />
Comment 2 David Britch 2017-11-13 12:41:13 UTC
I've created a sample that uses nullables, generics, and compiled bindings and eventually had no problems getting it working. The key was when specifying the x:DataType attribute.

If I used the blog post syntax (x:DataType="models:Deal"), some features worked, some didn't. For example:

    <StackLayout x:DataType="local:CompiledBindingsViewModel">

The above let me use compiled bindings for displaying view model properties. But a two-way binding had no luck (but no crash), and I was able to produce a crash when binding to a nullable. However, when I changed to the following syntax, all problems vanished (two-way bindings sprang into life, crashes no longer happened):

    <StackLayout x:DataType="{x:Type local:CompiledBindingsViewModel}">

Similarly, I had an identical issue when using compiled bindings on a DataTemplate. The following code caused a crash (the model uses nullables and generics):

                <DataTemplate x:DataType="local:Person">

But changing to the following made it work:

                <DataTemplate x:DataType="{x:Type local:Person}">

Note: I'm using Forms 2.4.1.2472.
Comment 3 Paul Kiar 2017-11-13 15:05:00 UTC
Fantastic, what's the resolution going forward?
1.  Should the x:Type part be always added?
2.  is there going to be a issue to fix the other syntax?
3.  perhaps error on the other syntax with a suggestion to use this syntax?
4.  Documentation change?

For now can I use the x:Type part of the syntax?  Will it be deprecated when fixed?