Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WinUI] Crash involving ObservableCollection and ContentView #21860

Closed
MartyIX opened this issue Apr 16, 2024 · 4 comments
Closed

[WinUI] Crash involving ObservableCollection and ContentView #21860

MartyIX opened this issue Apr 16, 2024 · 4 comments
Labels
platform/windows 🪟 s/needs-info Issue needs more info from the author t/bug Something isn't working

Comments

@MartyIX
Copy link
Contributor

MartyIX commented Apr 16, 2024

Description

I have a BindableLayout (here) representing tabs (think of browser tabs) and an ObservableCollection (here) representing those tabs.

Whenever I ask to switch the order of the tabs (click here), I get the following exception:

System.Runtime.InteropServices.COMException: 'No installed components were detected.

stacktrace:

   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
   at WinRT.DelegateExtensions.DynamicInvokeAbi(Delegate del, Object[] invoke_params)
   at ABI.System.Collections.Generic.IVectorMethods`1.Append(IObjectReference obj, T value)
   at ABI.System.Collections.Generic.IListMethods`1.Add(IObjectReference obj, T item)
   at Microsoft.UI.Xaml.Controls.UIElementCollection.Add(UIElement item)
   at Microsoft.Maui.Handlers.ContentViewHandler.UpdateContent(IContentViewHandler handler) in C:\maui\src\Core\src\Handlers\ContentView\ContentViewHandler.Windows.cs:line 26
   at Microsoft.Maui.Handlers.ContentViewHandler.MapContent(IContentViewHandler handler, IContentView page) in C:\maui\src\Core\src\Handlers\ContentView\ContentViewHandler.Windows.cs:line 46
   at Microsoft.Maui.PropertyMapper`2.<>c__DisplayClass5_0.<Add>b__0(IElementHandler h, IElement v) in C:\maui\src\Core\src\PropertyMapper.cs:line 172
   at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView) in C:\maui\src\Core\src\PropertyMapper.cs:line 47
   at Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler viewHandler, IElement virtualView) in C:\maui\src\Core\src\PropertyMapper.cs:line 82
   at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement view) in C:\maui\src\Core\src\Handlers\Element\ElementHandler.cs:line 79
   at Microsoft.Maui.Handlers.ViewHandler`2.SetVirtualView(IView view) in C:\maui\src\Core\src\Handlers\View\ViewHandlerOfT.cs:line 53
   at Microsoft.Maui.Handlers.ContentViewHandler.SetVirtualView(IView view) in C:\maui\src\Core\src\Handlers\ContentView\ContentViewHandler.Windows.cs:line 9
   at Microsoft.Maui.Handlers.ViewHandler`2.SetVirtualView(IElement view) in C:\maui\src\Core\src\Handlers\View\ViewHandlerOfT.cs:line 56
   at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler) in C:\maui\src\Controls\src\Core\Element\Element.cs:line 922
   at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value) in C:\maui\src\Controls\src\Core\Element\Element.cs:line 864
   at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler(IElementHandler value) in C:\maui\src\Controls\src\Core\VisualElement\VisualElement.cs:line 2061
   at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context) in C:\maui\src\Core\src\Platform\ElementExtensions.cs:line 96
   at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view, IMauiContext context) in C:\maui\src\Core\src\Platform\ElementExtensions.cs:line 127
   at Microsoft.Maui.Handlers.LayoutHandler.SetVirtualView(IView view) in C:\maui\src\Core\src\Handlers\Layout\LayoutHandler.Windows.cs:line 33
   at Microsoft.Maui.Handlers.ViewHandler`2.SetVirtualView(IElement view) in C:\maui\src\Core\src\Handlers\View\ViewHandlerOfT.cs:line 56
   at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler) in C:\maui\src\Controls\src\Core\Element\Element.cs:line 922
   at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value) in C:\maui\src\Controls\src\Core\Element\Element.cs:line 864
   at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler(IElementHandler value) in C:\maui\src\Controls\src\Core\VisualElement\VisualElement.cs:line 2061
   at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context) in C:\maui\src\Core\src\Platform\ElementExtensions.cs:line 96
   at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view, IMauiContext context) in C:\maui\src\Core\src\Platform\ElementExtensions.cs:line 127
   at Microsoft.Maui.Handlers.LayoutHandler.Insert(Int32 index, IView child) in C:\maui\src\Core\src\Handlers\Layout\LayoutHandler.Windows.cs:line 60
   at Microsoft.Maui.Handlers.LayoutHandler.MapInsert(ILayoutHandler handler, ILayout layout, Object arg) in C:\maui\src\Core\src\Handlers\Layout\LayoutHandler.cs:line 101
   at Microsoft.Maui.CommandMapper`2.<>c__DisplayClass6_0.<Add>b__0(IElementHandler h, IElement v, Object o) in C:\maui\src\Core\src\CommandMapper.cs:line 105
   at Microsoft.Maui.CommandMapper.InvokeCore(String key, IElementHandler viewHandler, IElement virtualView, Object args) in C:\maui\src\Core\src\CommandMapper.cs:line 33
   at Microsoft.Maui.CommandMapper.Invoke(IElementHandler viewHandler, IElement virtualView, String property, Object args) in C:\maui\src\Core\src\CommandMapper.cs:line 51
   at Microsoft.Maui.Handlers.ElementHandler.Invoke(String command, Object args) in C:\maui\src\Core\src\Handlers\Element\ElementHandler.cs:line 95
   at Microsoft.Maui.Controls.Layout.NotifyHandler(String action, Int32 index, IView view) in C:\maui\src\Controls\src\Core\Layout\Layout.cs:line 339
   at Microsoft.Maui.Controls.Layout.OnInsert(Int32 index, IView view) in C:\maui\src\Controls\src\Core\Layout\Layout.cs:line 323
   at Microsoft.Maui.Controls.Layout.Insert(Int32 index, IView child) in C:\maui\src\Controls\src\Core\Layout\Layout.cs:line 238
   at Microsoft.Maui.Controls.BindableLayout.Insert(IBindableLayout layout, Object item, Int32 index) in C:\maui\src\Controls\src\Core\BindableLayout\BindableLayout.cs:line 156
   at Microsoft.Maui.Controls.BindableLayoutController.<>c__DisplayClass39_0.<ItemsSourceCollectionChanged>b__0(Object item, Int32 index, Boolean _) in C:\maui\src\Controls\src\Core\BindableLayout\BindableLayout.cs:line 392
   at Microsoft.Maui.Controls.Internals.NotifyCollectionChangedEventArgsExtensions.Apply(NotifyCollectionChangedEventArgs self, Action`3 insert, Action`2 removeAt, Action reset) in C:\maui\src\Controls\src\Core\Internals\NotifyCollectionChangedEventArgsExtensions.cs:line 59
   at Microsoft.Maui.Controls.BindableLayoutController.ItemsSourceCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e) in C:\maui\src\Controls\src\Core\BindableLayout\BindableLayout.cs:line 391
   at Microsoft.Maui.Controls.WeakNotifyCollectionChangedProxy.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e) in C:\maui\src\Controls\src\Core\Internals\WeakEventProxy.cs:line 78
   at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at Maui.Controls.Sample.MainPage.Button_Clicked(Object sender, EventArgs e) in C:\maui\src\Controls\samples\Controls.Sample.Sandbox\MainPage.xaml.cs:line 29
   at Microsoft.Maui.Controls.Button.Microsoft.Maui.Controls.Internals.IButtonElement.PropagateUpClicked() in C:\maui\src\Controls\src\Core\Button\Button.cs:line 275
   at Microsoft.Maui.Controls.ButtonElement.ElementClicked(VisualElement visualElement, IButtonElement ButtonElementManager) in C:\maui\src\Controls\src\Core\Button\ButtonElement.cs:line 40
   at Microsoft.Maui.Controls.Button.SendClicked() in C:\maui\src\Controls\src\Core\Button\Button.cs:line 250
   at Microsoft.Maui.Controls.Button.Microsoft.Maui.IButton.Clicked() in C:\maui\src\Controls\src\Core\Button\Button.cs:line 484
   at Microsoft.Maui.Handlers.ButtonHandler.OnClick(Object sender, RoutedEventArgs e) in C:\maui\src\Core\src\Handlers\Button\ButtonHandler.Windows.cs:line 95
   at WinRT._EventSource_global__Microsoft_UI_Xaml_RoutedEventHandler.EventState.<GetEventInvoke>b__1_0(Object sender, RoutedEventArgs e)
   at ABI.Microsoft.UI.Xaml.RoutedEventHandler.Do_Abi_Invoke(IntPtr thisPtr, IntPtr sender, IntPtr e)

Steps to Reproduce

  1. Fetch https://github.com/MartyIX/maui/tree/feature/2024-04-16-ObservableCollection-crash (MartyIX@7de8a66)
  2. RunControls.Sample.Sandbox project
  3. Click "Change tab order" button

-> Crash (every time)

When I remove this line https://github.com/MartyIX/maui/blob/7de8a66ed902a9d346d93f520eec24a4fbb3a28b/src/Controls/samples/Controls.Sample.Sandbox/MainPage.xaml#L23, the issue is gone but obviously I want to display my custom control.

Link to public reproduction project repository

https://github.com/MartyIX/maui/tree/feature/2024-04-16-ObservableCollection-crash

Version with bug

8.0.20 SR4

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Windows, I was not able test on other platforms

Affected platform versions

Windows 10, Windows 11

Did you find any workaround?

No.

I have tried #8997 (comment) to no avail.

Relevant log output

No response

@MartyIX MartyIX added t/bug Something isn't working platform/windows 🪟 labels Apr 16, 2024
@bronteq
Copy link

bronteq commented Apr 16, 2024

Other open issues about ObservableCollection:
#20037
#18481
#21374

@MartyIX
Copy link
Contributor Author

MartyIX commented Apr 16, 2024

I added a commit MartyIX@d99835e to the branch. Thanks for help @roubachof.

-> I'm still testing if it fixes my issue but it seems what I was doing originally was wrong.

@PureWeen PureWeen added the s/needs-info Issue needs more info from the author label Apr 16, 2024
Copy link
Contributor

Hi @MartyIX. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@MartyIX
Copy link
Contributor Author

MartyIX commented Apr 16, 2024

My bad. It turns out that this line is the issue

https://github.com/MartyIX/maui/blob/7de8a66ed902a9d346d93f520eec24a4fbb3a28b/src/Controls/samples/Controls.Sample.Sandbox/MainPage.xaml#L23C25-L23C121

and converting the code to a custom control fixed my issue (MartyIX@d99835e)

@MartyIX MartyIX closed this as completed Apr 16, 2024
@github-actions github-actions bot locked and limited conversation to collaborators May 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
platform/windows 🪟 s/needs-info Issue needs more info from the author t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants