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...
Status: CONFIRMED
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 2.3.3
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
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:


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


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:
Status:
CONFIRMED

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">
    <Button.Behaviors>
        <local:Min3CharBehavior/>
    </Button.Behaviors>
</Button>

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

Xamarin.Forms 2.3.3.193
Xamarin 4.3.0.784
Xamarin.iOS 10.4.0.123
Xamarin.Android 7.1.0.41
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 2.3.3.193     BAD
Forms 2.3.4-pre2    BAD