You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
AvaloniaUI throws an InvalidOperationException when currentHandler.KeyBindings changes while handling a KeyBinding in the same list. This can happen when you load a new view using a command, and this new view has a HotKey.
System.InvalidOperationException
HResult=0x80131509
Message=Collection was modified; enumeration operation may not execute.
Source=System.Private.CoreLib
StackTrace:
at System.ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion()
at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at Avalonia.Input.KeyboardDevice.ProcessRawEvent(RawInputEventArgs e)
at Avalonia.Input.InputManager.ProcessInput(RawInputEventArgs e)
at Avalonia.Win32.WindowImpl.AppWndProc(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam)
at Avalonia.Win32.WindowImpl.WndProc(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam)
at Avalonia.Win32.Interop.UnmanagedMethods.DispatchMessage(MSG& lpmsg)
at Avalonia.Win32.Win32Platform.RunLoop(CancellationToken cancellationToken)
at Avalonia.Threading.Dispatcher.MainLoop(CancellationToken cancellationToken)
at Avalonia.Controls.ApplicationLifetimes.ClassicDesktopStyleApplicationLifetime.Start(String[] args)
at Avalonia.ClassicDesktopStyleApplicationLifetimeExtensions.StartWithClassicDesktopLifetime[T](T builder, String[] args, ShutdownMode shutdownMode)
at BindingsInvalidOperationException.Program.Main(String[] args) in C:\Users\Wouter\source\repos\BindingsInvalidOperationException\Program.cs:line 11
I created a repo which can be used to reproduce this issue.
How to trigger the crash:
Run the BindingsInvalidOperationException project
Press CTRL+N
2.1 This executes the AddTabCommand (see MainWindow.xaml -> Menu -> MenuItem -> HotKey)
2.2 The AddTabCommand adds a new TabPageViewModel to the TabControl
2.3 The TabControl loads a new TabPageView.xaml
2.4 The TabPageView has two buttons with a HotKey
2.5 I guess these new HotKeys are somehow added to the KeyBindings, which crashes the foreach loop.
An interesting fact is that it doesn't crash when you click the Add Tab MenuItem with your mouse. This is probably because the foreach loop is never executed in those cases.
Another funfact: if you click the Add Tab menu item once, so that it adds the HotKeys without crashing, you can then use CTRL+N to open more tabs and it doesn't crash. This is probably because it doesn't add the HotKeys because they already are inside the list.
I created this fix. It seems to work fine for my project, but I wouldn't know whether this is the best solution for the problem. I'll open a PR, but I'll also leave this issue open in case this solution is not acceptable.
This is all tested on 0.10.0-preview6.
The text was updated successfully, but these errors were encountered:
I'm experiencing this same issue on my project here. It works fine when the packages are version 0.10.0 but when I bump them up to 0.10.1 this problem occurs when using HotKeys (pressing Enter to save a new note).
grokys
added a commit
to Fusion86/Avalonia
that referenced
this issue
Jun 14, 2021
AvaloniaUI throws an InvalidOperationException when
currentHandler.KeyBindings
changes while handling a KeyBinding in the same list. This can happen when you load a new view using a command, and this new view has a HotKey.I created a repo which can be used to reproduce this issue.
How to trigger the crash:
2.1 This executes the AddTabCommand (see MainWindow.xaml -> Menu -> MenuItem -> HotKey)
2.2 The AddTabCommand adds a new TabPageViewModel to the TabControl
2.3 The TabControl loads a new TabPageView.xaml
2.4 The TabPageView has two buttons with a HotKey
2.5 I guess these new HotKeys are somehow added to the KeyBindings, which crashes the foreach loop.
An interesting fact is that it doesn't crash when you click the
Add Tab
MenuItem with your mouse. This is probably because theforeach
loop is never executed in those cases.Another funfact: if you click the
Add Tab
menu item once, so that it adds the HotKeys without crashing, you can then use CTRL+N to open more tabs and it doesn't crash. This is probably because it doesn't add the HotKeys because they already are inside the list.I created this fix. It seems to work fine for my project, but I wouldn't know whether this is the best solution for the problem. I'll open a PR, but I'll also leave this issue open in case this solution is not acceptable.
This is all tested on 0.10.0-preview6.
The text was updated successfully, but these errors were encountered: