XAML Parser / Compiler Bug

Just discovered that a extra '>' can slip through compilation and cause a runtime crash.

I have a DataTemplate in Resources that looks like this:

<ResourceDictionary> <converters:BooleanToObjectConverter x:Key="BooleanToObjectConverter" TrueValue="Picked" FalseValue="To Pick"> </converters:BooleanToObjectConverter> <DataTemplate x:Key="PickedHeaderTemplate"> <ViewCell> <StackLayout Padding="10,0,0,0" HorizontalOptions="FillAndExpand" Orientation="Horizontal" BindingContext="{Binding Source={x:Reference LotsListView}, Path=BindingContext}"> <Label Text="Picked" HorizontalOptions="Start"/> <Label Text="{Binding PickedLotsLabel, StringFormat ='{0}'}" HorizontalOptions="EndAndExpand"/> </StackLayout> > </ViewCell> </DataTemplate>

The extra '>' in 'Stacklayout' causes the crash.



  • adamkempadamkemp USInsider, Developer Group Leader mod

    The build process does not guarantee that the XAML is correct at build time. Aside from the .g.cs code generation, the XAML is parsed at runtime, and it is not difficult to construct XAML code that builds but throws an exception when parsed at runtime. I don't think this qualifies as a bug.

  • Adam.HillAdam.Hill USMember

    OK. I just added an extra '>' to a straight up WPF project and the compiler caught it. So Xamarin doesn't use any XAML tool bits in VS for anything? Its just text? I thought there was a XAML compiler and BAML in Xamarin.

    Oh well.

  • adamkempadamkemp USInsider, Developer Group Leader mod

    Xamarin handles XAML files itself because the way the XAML files are used is totally different. Even if Xamarin supported pre-compiling the XAML (which is a feature in development) then it still wouldn't use Microsoft's XAML parsing build tools. Those are just totally separate.

    As I said, for now the only thing the build does with XAML files for Xamarin.Forms is use them for generating the .g.cs files. If your file is corrupt in some way that at least allows that parser to work then it may get through the build process without an error. At runtime the file will be parsed by a different parser that is responsible for actually creating all of the real view objects and setting up all of the bindings. That is a much more complete parser, and it's not surprising that it catches things that the other parser doesn't. Or maybe the other parser just failed in such a way that it didn't generate anything but didn't report an error.

    Regardless, it is not expected that every error you can make in a XAML file is caught by the build system. That's just not a bug. It is possible for them to report an error in this case, but it doesn't surprise me too much that they didn't because nothing after that extraneous character was important.

Sign In or Register to comment.