Bug 53025 - No exception will be thrown when attempting to add Behavior to the incompatible type in XAML, but thrown when declared in code.
Summary: No exception will be thrown when attempting to add Behavior to the incompatib...
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 2.3.3
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2017-03-03 19:00 UTC by Frankie Foo
Modified: 2017-07-12 22:50 UTC (History)
4 users (show)

Tags: android, xaml, behaviors ac
Is this bug a regression?: ---
Last known good build:

XF project to demonstrate the bug (212.06 KB, application/x-zip-compressed)
2017-03-03 19:00 UTC, Frankie Foo

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

Description Frankie Foo 2017-03-03 19:00:42 UTC
Created attachment 20124 [details]
XF project to demonstrate the bug

XF behavior with the view set to Entry

class Min3CharBehavior: Xamarin.Forms.Behavior<Xamarin.Forms.Entry> {...}

If we call the following from code-behind, "System.InvalidOperationException: bindable not an instance of AssociatedType" will be thrown, which is expected.

var button = new Button();
button.Behaviors.Add(new Min3CharBehavior());

But if we do the same thing in XAML, no exception will be thrown. The app will become irresponsive until it crashed, and no exception is thrown even when running in debug mode.

<Button Text="click">

Tested on Android emulator and real device.
No test done on iOS device.

VS 2015 Enterprise Update 3 14.0.25431.01
Comment 1 Jimmy [MSFT] 2017-03-06 22:49:58 UTC
Thank you for filing this report! I was able to reproduce the issue when running the attached repro project on Android. On iOS it seems to work as expected and the exception gets thrown in both cases. I am confirming this report so the engineering team can look into this further.

### Test results
- On iOS an InvalidOperationException is thrown in both cases: XAML and code
- On Android the exception is only thrown when adding the invalid behavior with code

### Versions tested
Forms     BAD
Forms 2.3.4-pre2    BAD