Bug 34379 - Hiding Bindable Properties throws "Sequence contains more than one matching element"
Summary: Hiding Bindable Properties throws "Sequence contains more than one matching e...
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 1.5.0
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Stephane Delcroix
URL:
Depends on:
Blocks:
 
Reported: 2015-09-29 04:34 UTC by FieldstrikeMobile
Modified: 2016-04-13 19:55 UTC (History)
2 users (show)

Tags: AC xaml
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:
Status:
RESOLVED FIXED

Description FieldstrikeMobile 2015-09-29 04:34:20 UTC
I am overriding `BoxView` in my `PCL` to make my own `ShapeView`

I would like to hide the `BoxView` color property and have a `Color` property on `ShapeView` so that I can raise a property changed when it changes and reflect this in the UI.

	public class ShapeView : BoxView
	{
        public static event EventHandler ColorChanged;
        protected static void OnColorChanged(ShapeView view)
        {
            if (ColorChanged != null)
            {
                ColorChanged(view, new EventArgs());
            }
        }

        public new static readonly BindableProperty ColorProperty = BindableProperty.Create<ShapeView, Color>(s => s.Color, Color.Transparent,
            propertyChanged: (b, o, n) =>
            {
                ((ShapeView)b).Color = n;
                OnColorChanged((ShapeView)b);
            });

        public Color Color
        {
            get { return (Color)GetValue(ColorProperty); }
            set { SetValue(ColorProperty, value); }
        }
        
        }

but when I put this control into a page I get the following error:

 System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: Sequence contains more than one matching element
09-29 09:28:07.484 I/MonoDroid(17565):   at System.Linq.Enumerable.Single[FieldInfo] (IEnumerable`1 source, System.Func`2 predicate, Fallback fallback) [0x0003d] in <filename unknown>:0 
09-29 09:28:07.484 I/MonoDroid(17565):   at System.Linq.Enumerable.SingleOrDefault[FieldInfo] (IEnumerable`1 source, System.Func`2 predicate) [0x00007] in <filename unknown>:0 
09-29 09:28:07.484 I/MonoDroid(17565):   at Xamarin.Forms.ReflectionExtensions.GetField (System.Type type, System.Func`2 predicate) [0x00006] in <filename unknown>:0 
09-29 09:28:07.484 I/MonoDroid(17565):   at Xamarin.Forms.BindablePropertyConverter.ConvertFrom (System.Type type, System.String propertyName, IXmlLineInfo lineinfo) [0x00017] in <filename unknown>:0 
09-29 09:28:07.484 I/MonoDroid(17565):   at Xamarin.Forms.BindablePropertyConverter.Xamarin.Forms.IExtendedTypeConverter.ConvertFrom (System.Globalization.CultureInfo culture, System.Object value, IServiceProvider serviceProvider) [0x0013e] in <filename unknown>:0 
09-29 09:28:07.484 I/MonoDroid(17565):   at Xamarin.Forms.Xaml.TypeConversionExtensions.ConvertTo (System.Object value, System.Type toType, System.Func`1 getConverter, IServiceProvider serviceProvider) [0x0003d] in <filename unknown>:0 
09-29 09:28:07.484 I/MonoDroid(17565):   at Xamarin.Forms.Xaml.TypeConversionExtensions.ConvertTo (System.Object value, System.Type toType, System.Func`1 minfoRetriever, IServiceProvider serviceProvider) [0x00021] in <filename unknown>:0 
09-29 09:28:07.484 I/MonoDroid(17565):   at Xamarin.Forms.Xaml.ApplyPropertiesVisitor.SetPropertyValue (System.Object xamlelement, XmlName propertyName, System.Object value, Xamarin.Forms.BindableObject rootElement, INode node, Xamarin.Forms.Xaml.HydratationContext context, IXmlLineInfo lineInfo) [0x00357] in <filename unknown>:0 
09-29 09:28:07.484 I/MonoDroid(17565):   at Xamarin.Forms.Xaml.ApplyPropertiesVisitor.Visit (Xamarin.Forms.Xaml.ValueNode node, INode parentNode) [0x0005e] in <filename unknown>:0 
09-29 09:28:07.484 I/MonoDroid(17565):   at Xamarin.Forms.Xaml.ValueNode.Accept (IXamlNodeVisitor visitor, INode parentNode) [0x00000] in <filename unknown>:0 
09-29 09:28:07.484 I/MonoDroid(17565):   at Xamarin.Forms.Xaml.ElementNode.Accept (IXamlNodeVisitor visitor, INode parentNode) [0x00054] in <filename unknown>:0 
09-29 09:28:07.484 I/MonoDroid(17565):   at Xamarin.Forms.Xaml.ElementNode.Accept (IXamlNodeVisitor visitor, INode parentNode) [0x00089] in <filename unknown>:0 
09-29 09:28:07.484 I/MonoDroid(17565):   at Xamarin.Forms.Xaml.ElementNode.Accept (IXamlNodeVisitor visitor, INode parentNode) [0x00054] in <filename unknown>:0 
09-29 09:28:07.484 I/MonoDroid(17565):   at Xamarin.Forms.Xaml.ElementNode.Accept (IXamlNodeVisitor visitor, INode parentNode) [0x00089] in <filename unknown>:0 
09-29 09:28:07.484 I/MonoDroid(17565):   at Xamarin.Forms.Xaml.ElementNode.Accept (IXamlNodeVisitor visitor, INode parentNode) [0x00089] in <filename unknown>:0 
09-29 09:28:07.484 I/MonoDroid(17565):   at Xamarin.Forms.Xaml.ElementNode.Accept (IXamlNodeVisitor visitor, INode parentNode) [0x00089] in <filename unknown>:0 
09-29 09:28:07.484 I/MonoDroid(17565):   at Xamarin.Forms.Xaml.RootNode.Accept (IXamlNodeVisitor visitor, INode parentNode) [0x00064] in <filename unknown>:0 
09-29 09:28:07.484 I/MonoDroid(17565):   at Xamarin.Forms.Xaml.XamlLoader.Load (Xamarin.Forms.BindableObject view, System.String xaml) [0x000cb] in <filename unknown>:0 
09-29 09:28:07.484 I/MonoDroid(17565):   at Xamarin.Forms.Xaml.XamlLoader.Load (Xamarin.Forms.BindableObject view, System.Type callingType) [0x00029] in <filename unknown>:0 
09-29 09:28:07.484 I/MonoDroid(17565):   at Xamarin.Forms.Xaml.Extensions.LoadFromXaml[PinView] (FieldStrikeMove.Forms.Views.PinView view, System.Type callingType) [0x00000] in <filename unknown>:0 
09-29 09:28:07.489 I/MonoDroid(17565):   at FieldStrikeMove.Forms.Views.PinView.InitializeComponent () [0x00001] in d:\tfs\FieldStrike\FieldStrikeMove\FieldStrikeMove.Forms\obj\Debug\FieldStrikeMove.Forms.Views.PinView.xaml.g.cs:21 
09-29 09:28:07.489 I/MonoDroid(17565):   at FieldStrikeMove.Forms.Views.PinView..ctor () [0x00008] in d:\tfs\FieldStrike\FieldStrikeMove\FieldStrikeMove.Forms\Views\PinView.xaml.cs:15 
09-29 09:28:07.489 I/MonoDroid(17565):   at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&)
09-29 09:28:07.489 I/MonoDroid(17565):   at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00002] in <filename unknown>:0 
09-29 09:28:07.489 I/MonoDroid(17565):   --- End of inner exception stack trace ---
09-29 09:28:07.489 I/MonoDroid(17565): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <IL 0x00011, 0x00078>
09-29 09:28:07.489 I/MonoDroid(17565): at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>m__0 (object) <IL 0x00006, 0x0006b>
09-29 09:28:07.489 I/MonoDroid(17565): at Android.App.SyncContext/<Post>c__AnonStorey0.<>m__0 () [0x00000] in /Users/builder/data/lanes/2058/58099c53/source/monodroid/src/Mono.Android/src/Android.App/SyncContext.cs:18
09-29 09:28:07.489 I/MonoDroid(17565): at Java.Lang.Thread/RunnableImplementor.Run () [0x0000b] in /Users/builder/data/lanes/2058/58099c53/source/monodroid/src/Mono.Android/src/Java.Lang/Thread.cs:36
09-29 09:28:07.489 I/MonoDroid(17565): at Java.Lang.IRunnableInvoker.n_Run (intptr,intptr) [0x00009] in /Users/builder/data/lanes/2058/58099c53/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Java.Lang.IRunnable.cs:71
09-29 09:28:07.489 I/MonoDroid(17565): at (wrapper dynamic-method) object.2c5be2fc-2793-48f9-a986-8218bcdf8a5f (intptr,intptr) <IL 0x00011, 0x0003b>
09-29 09:28:07.504 W/Xamarin.Insights(17565): Warning: Unhandled exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: Sequence contains more than one matching element
09-29 09:28:07.504 W/Xamarin.Insights(17565):   at System.Linq.Enumerable.Single[FieldInfo] (IEnumerable`1 source, System.Func`2 predicate, Fallback fallback) [0x0003d] in <filename unknown>:0 
09-29 09:28:07.504 W/Xamarin.Insights(17565):   at System.Linq.Enumerable.SingleOrDefault[FieldInfo] (IEnumerable`1 source, System.Func`2 predicate) [0x00007] in <filename unknown>:0 
09-29 09:28:07.504 W/Xamarin.Insights(17565):   at Xamarin.Forms.ReflectionExtensions.GetField (System.Type type, System.Func`2 predicate) [0x00006] in <filename unknown>:0 
09-29 09:28:07.504 W/Xamarin.Insights(17565):   at Xamarin.Forms.BindablePropertyConverter.ConvertFrom (System.Type type, System.String propertyName, IXmlLineInfo lineinfo) [0x00017] in <filename unknown>:0 
09-29 09:28:07.504 W/Xamarin.Insights(17565):   at Xamarin.Forms.BindablePropertyConverter.Xamarin.Forms.IExtendedTypeConverter.ConvertFrom (System.Globalization.CultureInfo culture, System.Object value, IServiceProvider serviceProvider) [0x0013e] in <filename unknown>:0 
09-29 09:28:07.504 W/Xamarin.Insights(17565):   at Xamarin.Forms.Xaml.TypeConversionExtensions.ConvertTo (System.Object value, System.Type toType, System.Func`1 getConverter, IServiceProvider serviceProvider) [0x0003d] in <filename unknown>:0 
09-29 09:28:07.504 W/Xamarin.Insights(17565):   at Xamarin.Forms.Xaml.TypeConversionExtensions.ConvertTo (System.Object value, System.Type toType, System.Func`1 minfoRetriever, IServiceProvider serviceProvider) [0x00021] in <filename unknown>:0 
09-29 09:28:07.504 W/Xamarin.Insights(17565):   at Xamarin.Forms.Xaml.ApplyPropertiesVisitor.SetPropertyValue (System.Object xamlelement, XmlName propertyName, System.Object value, Xamarin.Forms.BindableObject rootElement, INode node, Xamarin.Forms.Xaml.HydratationContext context, IXmlLineInfo lineInfo) [0x00357] in <filename unknown>:0 
09-29 09:28:07.504 W/Xamarin.Insights(17565):   at Xamarin.Forms.Xaml.ApplyPropertiesVisitor.Visit (Xamarin.Forms.Xaml.ValueNode node, INode parentNode) [0x0005e] in <filename unknown>:0 
09-29 09:28:07.504 W/Xamarin.Insights(17565):   at Xamarin.Forms.Xaml.ValueNode.Accept (IXamlNodeVisitor visitor, INode parentNode) [0x00000] in <filename unknown>:0 
09-29 09:28:07.504 W/Xamarin.Insights(17565):   at Xamarin.Forms.Xaml.ElementNode.Accept (IXamlNodeVisitor visitor, INode parentNode) [0x00054] in <filename unknown>:0 
09-29 09:28:07.504 W/Xamarin.Insights(17565):   at Xamarin.Forms.Xaml.ElementNode.Accept (IXamlNodeVisitor visitor, INode parentNode) [0x00089] in <filename unknown>:0 
09-29 09:28:07.504 W/Xamarin.Insights(17565):   at Xamarin.Forms.Xaml.ElementNode.Accept (IXamlNodeVisitor visitor, INode parentNode) [0x00054] in <filename unknown>:0 
09-29 09:28:07.504 W/Xamarin.Insights(17565):   at Xamarin.Forms.Xaml.ElementNode.Accept (IXamlNodeVisitor visitor, INode parentNode) [0x00089] in <filename unknown>:0 
09-29 09:28:07.504 W/Xamarin.Insights(17565):   at Xamarin.Forms.Xaml.ElementNode.Accept (IXamlNodeVisitor visitor, INode parentNode) [0x00089] in <filename unknown>:0 
09-29 09:28:07.504 W/Xamarin.Insights(17565):   at Xamarin.Forms.Xaml.ElementNode.Accept (IXamlNodeVisitor visitor, INode parentNode) [0x00089] in <filename unknown>:0 
09-29 09:28:07.504 W/Xamarin.Insights(17565):   at Xamarin.Forms.Xaml.RootNode.Accept (IXamlNodeVisitor visitor, INode parentNode) [0x00064] in <filename unknown>:0 
09-29 09:28:07.504 W/Xamarin.Insights(17565):   at Xamarin.Forms.Xaml.XamlLoader.Load (Xamarin.Forms.BindableObject view, System.String xaml) [0x000cb] in <filename unknown>:0 
09-29 09:28:07.504 W/Xamarin.Insights(17565):   at Xamarin.Forms.Xaml.XamlLoader.Load (Xamarin.Forms.BindableObject view, System.Type callingType) [0x00029] in <filename unknown>:0 
09-29 09:28:07.504 W/Xamarin.Insights(17565):   at Xamarin.Forms.Xaml.Extensions.LoadFromXaml[PinView] (FieldStrikeMove.Forms.Views.PinView view, System.Type callingType) [0x00000] in <filename unknown>:0 
09-29 09:28:07.504 W/Xamarin.Insights(17565):   at FieldStrikeMove.Forms.Views.PinView.InitializeComponent () [0x00001] in d:\tfs\FieldStrike\FieldStrikeMove\FieldStrikeMove.Forms\obj\Debug\FieldStrikeMove.Forms.Views.PinView.xaml.g.cs:21 
09-29 09:28:07.504 W/Xamarin.Insights(17565):   at FieldStrikeMove.Forms.Views.PinView..ctor () [0x00008] in d:\tfs\FieldStrike\FieldStrikeMove\FieldStrikeMove.Forms\Views\PinView.xaml.cs:15 
09-29 09:28:07.504 W/Xamarin.Insights(17565):   at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&)
09-29 09:28:07.504 W/Xamarin.Insights(17565):   at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00002] in <filename unknown>:0 
09-29 09:28:07.504 W/Xamarin.Insights(17565):   --- End of inner exception stack trace ---
09-29 09:28:07.504 W/Xamarin.Insights(17565): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <IL 0x00011, 0x00078>
09-29 09:28:07.504 W/Xamarin.Insights(17565): at System.Runtime.CompilerServices.AsyncMe
Comment 1 Stephane Delcroix 2015-10-01 04:45:25 UTC
By the trace, I guess you're then trying to define a Style in XAML for that ShapeView. Is that right ?
Comment 2 FieldstrikeMobile 2015-10-01 04:48:52 UTC
Not a Style. I am however defining a DataTrigger which I am looking to change the Color property when the criteria are met
Comment 3 Stephane Delcroix 2015-10-01 05:06:48 UTC
I'm confirming this. Note that, even with the crash fixed, we can not guarantee that the scenario you are trying to implement (overriding Bindable Properties) will work.
Comment 4 FieldstrikeMobile 2015-10-01 05:09:44 UTC
I managed to get it to work I just had to call my bindable property ShapeColor instead.

I would have thought it would be a case of changing the SingleOrDefault to FirstOrDefault. And make sure First is the overriding property
Comment 5 Stephane Delcroix 2015-10-01 09:17:23 UTC
You're right that it's a matter of changing the FirstOrDefault to something else. And a fix is coming so it no longer crash.

I just have no idea what you have in mind when overriding a BP, how you expect it to behave at the renderer level, etc... Your scenario might not be supported by X.F. That's what I meant.