AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
26.05k stars 2.25k forks source link

``System.InvalidOperationException` thown by `ManagedFileChooserSources` #13111

Open lontivero opened 1 year ago

lontivero commented 1 year ago

Describe the bug

System.InvalidOperationException is thrown in occasionally

This problem was originally reported in Wasabi: https://github.com/zkSNACKs/WalletWasabi/issues/10286

[1] CRITICAL    Program.Main (132)  System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
   at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
   at System.Linq.Enumerable.SelectIListIterator`2.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.ToArray()
   at Avalonia.Dialogs.ManagedFileChooserSources.DefaultGetFileSystemRoots() in /_/src/Avalonia.Dialogs/ManagedFileChooserSources.cs:line 56
   at Avalonia.Dialogs.ManagedFileChooserSources.DefaultGetAllItems(ManagedFileChooserSources sources) in /_/src/Avalonia.Dialogs/ManagedFileChooserSources.cs:line 28
   at Avalonia.Dialogs.ManagedFileChooserSources.GetAllItems() in /_/src/Avalonia.Dialogs/ManagedFileChooserSources.cs:line 23
   at Avalonia.Dialogs.ManagedFileChooserViewModel.RefreshQuickLinks(ManagedFileChooserSources quickSources) in /_/src/Avalonia.Dialogs/ManagedFileChooserViewModel.cs:line 104
   at Avalonia.Dialogs.ManagedFileChooserViewModel.<>c__DisplayClass56_0.<.ctor>b__0(EventPattern`1 x) in /_/src/Avalonia.Dialogs/ManagedFileChooserViewModel.cs:line 123
   at System.Reactive.AnonymousSafeObserver`1.OnNext(T value) in /_/Rx.NET/Source/src/System.Reactive/AnonymousSafeObserver.cs:line 54
   at System.Reactive.ObserveOnObserverNew`1.DrainStep(ConcurrentQueue`1 q) in /_/Rx.NET/Source/src/System.Reactive/Internal/ScheduledObserver.cs:line 559
   at System.Reactive.ObserveOnObserverNew`1.DrainShortRunning(IScheduler recursiveScheduler) in /_/Rx.NET/Source/src/System.Reactive/Internal/ScheduledObserver.cs:line 516
   at Avalonia.Threading.AvaloniaScheduler.<>c__DisplayClass4_1`1.<Schedule>b__1() in /_/src/Avalonia.Base/Threading/AvaloniaScheduler.cs:line 45
   at Avalonia.Threading.JobRunner.RunJobs(Nullable`1 priority) in /_/src/Avalonia.Base/Threading/JobRunner.cs:line 37
   at Avalonia.X11.X11PlatformThreading.CheckSignaled() in /_/src/Avalonia.X11/X11PlatformThreading.cs:line 164
   at Avalonia.X11.X11PlatformThreading.RunLoop(CancellationToken cancellationToken) in /_/src/Avalonia.X11/X11PlatformThreading.cs:line 205
   at Avalonia.Threading.Dispatcher.MainLoop(CancellationToken cancellationToken) in /_/src/Avalonia.Base/Threading/Dispatcher.cs:line 65
   at Avalonia.Controls.ApplicationLifetimes.ClassicDesktopStyleApplicationLifetime.Start(String[] args) in /_/src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs:line 120
   at Avalonia.ClassicDesktopStyleApplicationLifetimeExtensions.StartWithClassicDesktopLifetime[T](T builder, String[] args, ShutdownMode shutdownMode) in /_/src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs:line 209
   at WalletWasabi.Fluent.Desktop.Program.Main(String[] args)

To Reproduce

It is not clear how to reproduce it.

Expected behavior

N/A

Screenshots

NA

Environment

Additional context

It seems MountedVolumes property is modified during iteration time. (see: https://github.com/AvaloniaUI/Avalonia/blob/a7725b0ca6625f5d35fffc79b94012d38718e8ad/src/Avalonia.Dialogs/Internal/ManagedFileChooserSources.cs#L55) It could make sense to materialize the collection first.

timunie commented 1 year ago

0.10.18 is pretty outdated. Can you double-check using 11.0 if the issue is still present?

Not sure if 0.10 will get any fixes. But if you want to file a PR to the 0.10.x branch, you may have luck it might make it into the next 0.10.x version.

lontivero commented 1 year ago

Can you double-check using 11.0 if the issue is still present?

Sure. The issue is a bit hard to reproduce but I think we can do it, yes. @wieslawsoltes @soosr

0.10.18 is pretty outdated

Yes, but this code didn't change much and the iteration against a mutable collection is still there. Anyway, let us see if we can verify the problem is there in 11.

timunie commented 1 year ago

if the issue is still present and this is an easy fix, a PR is still welcome :-)