Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
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
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.
Created attachment 13990 [details]
When control (TestControl in sample) have BindableProperty with collection type (i.e. ObservableCollection<Label> like TestCollection in sample) that have default value of null and it is added to Xaml page in following way:
Xaml parser throws critical exception:
Position 12:10. Cannot assign property "TestCollection": type mismatch between "Xamarin.Forms.Label" and "System.Collections.ObjectModel.ObservableCollection`1[Xamarin.Forms.Label]"
Instead of NullReferenceException, because Label cannot be added to collection when it is null. This way it works in XAML in WPF framework.
Property XXX.ObservableCollection is null
w System.Xaml.XamlWriter.WriteNode(XamlReader reader)
Moreover it is possible to do this:
Which I doubt is usefull at all, since intuitive thing to do is to add items to collection not initiate collection itself first. In WPF it is simply prohibited and it gave following error:
Error A value of type 'ObservableCollection' cannot be added to a collection or dictionary of type 'ObservableCollection'. XXX XXXX\MainWindow.xaml 45
I think this is more sane behavior. Xamarin error is much more confusing.
Your syntax will work if you initialize the collection to a non-null value.
Given the way our parser works, the reported message is as accurate as possible. Thanks for the suggestion for detecting this special case and handling it with a custom error message. We will consider it.
the XF team