Bug 27740 - Invalid Binding Markup Works, but Should Provide an Warning/Compile Error
Summary: Invalid Binding Markup Works, but Should Provide an Warning/Compile Error
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.3.5
Hardware: PC All
: Low normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2015-03-06 16:09 UTC by Michael
Modified: 2016-04-09 16:11 UTC (History)
5 users (show)

Tags: 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 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:

Description Michael 2015-03-06 16:09:51 UTC

Invalid binding syntax is allowed in Xaml expressions and are not caught at compile-time.  Here is an example:

(the binding is missing the trailing '}')

In Silverlight/WPF this would produce a build error.

In Xamarin.Forms, the provided example actually works in runtime, which is pretty cool. :)

However, this could lead to other anomalies, so it would be nice to get a warning (at the very least) during compile time to know that this is there.

As an aside, I do have to say that Xamarin.Forms as a whole is just really impressive all-around.  If these are the types of issues I am finding, then I would say that is a testament to the really great work you are doing.  I am really impressed with your work!

Thanks again and please let me know if you have any questions/comments around this.
Comment 1 Michael 2015-03-06 17:44:57 UTC
My little "aside" that I mentioned above inspired me to write a forum post outlining my efforts for the past week.  You can see the post here:

Again, much respect and appreciation to the team!
Comment 2 Bryan Hunter 2016-04-09 01:52:56 UTC
In the current stable version of Forms, invalid bindings will produce compile-time errors if XAML compilation is turned on. With the following attribute 

<Label x:Name="Text" Text="{Binding Source={{StaticResource KeyName" VerticalOptions="Center" HorizontalOptions="Center" />

yields this compile-time error:
(24,24): Error: Position 9:24. Markup expression missing its closing tag

Interestingly, the single missing tag in your sample still doesn't produce an error, but as you say it behaves fine at runtime. 

Does the current state resolve the issue for you?
Comment 3 Michael 2016-04-09 09:16:01 UTC
Well to start with... it's great to see you are looking into these issues, even if it's over a year now since they were submitted.  Honestly I thought these were all left for dead. :P

Everything does look good now in what you suggest.  However I am a little confused on what you mean by "missing single tag doesn't produce an error".  It seems to me that the sample that I provide and the sample you provide above are the same?  Or are you saying that in my sample with the XamlCompilationAttribute applied it still doesn't produce an error?

Thanks again,
Comment 4 Bryan Hunter 2016-04-09 15:17:22 UTC
Your sample was 
<Label x:Name="Text" Text="{Binding Source={StaticResource KeyName}" VerticalOptions="Center" HorizontalOptions="Center" />

I haven't dug into the machinery of how the single missing close "}" is smoothed over by the XAML compiler, but it is. In my (truly broken) expression, the XAML Compiler couldn't make sense of it, and does what we all want it to: it creates a compile-time error. 

If you are satisfied, we will make this one resolved.
Comment 5 Michael 2016-04-09 15:25:26 UTC
OK I see.  So if you have the XamlCompilationAttribute applied, you get an error at compile-time and cannot continue.  Otherwise, it works as before, and you are saying that it is not clear as to why that is.  Is this new compile-time checking using the same parser?  It sounds like there is a new Xaml Compiler component (which checks for these conditions via the aforementioned attribute) and a parser that just doesn't care. :)

If that is the state of things, then yes, that totally works for me. Thank you for the engagement and dialogue!
Comment 6 Bryan Hunter 2016-04-09 16:11:59 UTC
Yes, the XAML Compiler (aka XamlC) was introduced in 1.5.1. It converts the XAML into IL at compile time.