This issue is listed here: #9183
It was closed by this commit: c87b733
That fix though was applied to class Xamarin.Forms.Core/Interactivity/AttachedCollection.cs file. But the stack trace in the error I submitted originates in the Xamarin.Forms.Core/Style.cs class.
This error from the original issue is still occurring.
@rlasker-b2w
@rlasker3
@ngalicoco
Do you have a repro?
@hartez thoughts?
@PureWeen Unfortunately I am unable to reproduce in development, so I'm not sure of the cause, but I have 1.3k of these errors logged in AppCenter just for iOS alone. The only hint I can give is that it always seems to originate from the Label object's default constructor.
Xamarin.Forms: Style+<>c.b__47_0 (System.WeakReference1[T] t) System.Collections.Generic: List1[T].RemoveAll (System.Predicate1[T] match) Xamarin.Forms: Style.CleanUpWeakReferences () Xamarin.Forms.Style.Xamarin.Forms: IStyle.Apply (Xamarin.Forms.BindableObject bindable) Xamarin.Forms: MergedStyle.SetStyle (Xamarin.Forms.IStyle implicitStyle, System.Collections.Generic.IList1[T] classStyles, Xamarin.Forms.IStyle style)
Xamarin.Forms: MergedStyle.set_ImplicitStyle (Xamarin.Forms.IStyle value)
Xamarin.Forms: MergedStyle.OnImplicitStyleChanged ()
Xamarin.Forms: MergedStyle.b__30_0 (Xamarin.Forms.BindableObject bindable, System.Object oldvalue, System.Object newvalue)
Xamarin.Forms: BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent)
Xamarin.Forms: BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes)
Xamarin.Forms: BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes)
Xamarin.Forms: Element.OnResourceChanged (Xamarin.Forms.BindableProperty property, System.Object value)
Xamarin.Forms: Element.OnSetDynamicResource (Xamarin.Forms.BindableProperty property, System.String key)
Xamarin.Forms: BindableObject.SetDynamicResource (Xamarin.Forms.BindableProperty property, System.String key, System.Boolean fromStyle)
Xamarin.Forms: BindableObject.SetDynamicResource (Xamarin.Forms.BindableProperty property, System.String key)
Xamarin.Forms: MergedStyle.RegisterImplicitStyles ()
Xamarin.Forms.MergedStyle: Xamarin.Forms.MergedStyle..ctor (System.Type targetType, Xamarin.Forms.BindableObject target) <0x105406830 + 0x0010b> in <8e9ab226c9a54dbdb9366a1fb41e66e3#4a869c4f0377cf5f19ee7f49671e008e>:0
Xamarin.Forms.NavigableElement: Xamarin.Forms.NavigableElement..ctor () <0x105437e90 + 0x0006f> in <8e9ab226c9a54dbdb9366a1fb41e66e3#4a869c4f0377cf5f19ee7f49671e008e>:0
Xamarin.Forms.VisualElement: Xamarin.Forms.VisualElement..ctor () <0x105482ab0 + 0x000ef> in <8e9ab226c9a54dbdb9366a1fb41e66e3#4a869c4f0377cf5f19ee7f49671e008e>:0
Xamarin.Forms.View: Xamarin.Forms.View..ctor () <0x10547e120 + 0x0010b> in <8e9ab226c9a54dbdb9366a1fb41e66e3#4a869c4f0377cf5f19ee7f49671e008e>:0
Xamarin.Forms.Label: Xamarin.Forms.Label..ctor () <0x1053f3670 + 0x00017> in <8e9ab226c9a54dbdb9366a1fb41e66e3#4a869c4f0377cf5f19ee7f49671e008e>:0
The only additional information I can give you from our side of the code is that the label is being added to a stackpanel in code and we are setting the StyleClass property on it.
Children.Add(titleLabel = new Label()
{
StyleClass = styleClass ?? new string[] { ComponentType.None.ToString() },
Text = text,
TextColor = Color.FromHex(color)
});
For us it is the same case, hard to reproduce in development or debugging.
It seems to happen more when user tries to navigate between pages with heavy UI (scrollview, listview or stacklayout) quickly, not allowing the entire UI to load/renderer
And it happens on both iOS and Android irrespective of the operation system versions.
Happens on latest iOS 13 and Android 10 too
Upgraded to version 4.5.0.530 and we are still seeing exceptions coming from Styles.CleaUpWeakReferences though the nature of the exception is now different. Before we were seeing a null reference exception:
Style+<>c.
System.AggregateException: Object reference not set to an instance of an object
Xamarin.Forms
Style+<>c.1[T] t)
System.Collections.Generic
List1[T].RemoveAll (System.Predicate`1[T] match) Xamarin.Forms
Style.CleanUpWeakReferences ()
Now we are getting index out of range exception:
Array.Clear (System.Array array, System.Int32 index, System.Int32 length)
System.IndexOutOfRangeException: length < 0
System
Array.Clear (System.Array array, System.Int32 index, System.Int32 length) System.Collections.Generic
List1[T].RemoveAll (System.Predicate1[T] match) Xamarin.Forms
Style.CleanUpWeakReferences ()
The rest of the stack traces are identical and matches the stack traces I've posted before.
@rlasker-b2w Could you open a separate issue for this new exception, and post your stack trace? I'll need to put in a separate fix and a new unit test for this scenario.