dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.98k stars 1.71k forks source link

Collection was modified after the enumerator was instantiated. #23597

Open evolcano opened 1 month ago

evolcano commented 1 month ago

Description

When I add a child to grid, it sometime trigger a error: Collection was modified after the enumerator was instantiated. This grid has none parent yet, grid and child is just created in this UI thread.

image

*CurrentNode is extended form StackLayout which has some hierarchy childs.

Steps to Reproduce

Can not repeat for have no regularity .

Link to public reproduction project repository

No response

Version with bug

8.0.70 SR7

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

net8.0-windows10.0.19041.0

Did you find any workaround?

No

Relevant log output

System.InvalidOperationException
  HResult=0x80131509
  Message=Collection was modified after the enumerator was instantiated.
  Source=System.Linq
  StackTrace:
   at System.Linq.Enumerable.TryGetLast[TSource](IEnumerable`1 source, Boolean& found)
   at System.Linq.Enumerable.Last[TSource](IEnumerable`1 source)
   at Microsoft.Maui.Controls.SetterSpecificityList.GetSpecificityAndValue()
   at Microsoft.Maui.Controls.BindableObject.GetValue(BindableProperty property)
   at Microsoft.Maui.Controls.VisualElement.CoerceIsEnabledProperty(BindableObject bindable, Object value)
   at Microsoft.Maui.Controls.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes, SetterSpecificity specificity)
   at Microsoft.Maui.Controls.BindableObjectExtensions.RefreshPropertyValue(BindableObject self, BindableProperty property, Object value)
   at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.Controls.IPropertyPropagationController.PropagatePropertyChanged(String propertyName)
   at Microsoft.Maui.Controls.Internals.PropertyPropagationExtensions.PropagatePropertyChanged(String propertyName, Element element, IEnumerable children)
   at Microsoft.Maui.Controls.NavigableElement.OnParentSet()
   at Microsoft.Maui.Controls.Element.SetParent(Element value)
   at Microsoft.Maui.Controls.Element.OnChildAdded(Element child)
   at Microsoft.Maui.Controls.VisualElement.OnChildAdded(Element child)
   at Microsoft.Maui.Controls.Layout.Add(IView child)
   at Microsoft.Maui.Controls.GridExtensions.AddWithSpan(Grid grid, IView view, Int32 row, Int32 column, Int32 rowSpan, Int32 columnSpan)
github-actions[bot] commented 1 month ago

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

PureWeen commented 1 month ago

@StephaneDelcroix thoughts?

StephaneDelcroix commented 1 month ago

no thoughts, but easy to fix