WindowsCommunityToolkit
WindowsCommunityToolkit copied to clipboard
Fatal crash using TokenizingTextBox with SelectionMode=None (uwp)
Describe the bug
As the title says:
<tk:TokenizingTextBox SelectionMode="None" />
and
<tk:TokenizingTextBox SelectionMode="Single" />
Both of these cause the following failure when pressing backspace:
"System.Exception: Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))
at System.Runtime.InteropServices.WindowsRuntime.IVector`1.Append(T value)
at System.Runtime.InteropServices.WindowsRuntime.VectorToCollectionAdapter.Add[T](T item)
at Microsoft.Toolkit.Uwp.UI.Controls.TokenizingTextBox.SelectNewItem(TokenizingTextBoxItem item, Int32 increment, Func`2 testFunc)
at Microsoft.Toolkit.Uwp.UI.Controls.TokenizingTextBox.SelectPreviousItem(TokenizingTextBoxItem item)
at "
Regression
No response
Reproducible in sample app?
- [x] This bug can be reproduced in the sample app.
Steps to reproduce
1. Clone this repo: https://github.com/0xNF/TokenizingTextBoxCrash
2. Create a new tag by pressing enter with some text in the Text Box
3. Press backspace a few times with the textbox still focused
4. crash
Expected behavior
Not crashing
Screenshots
No response
Windows Build Number
- [ ] Windows 10 1809 (Build 17763)
- [ ] Windows 10 1903 (Build 18362)
- [ ] Windows 10 1909 (Build 18363)
- [X] Windows 10 2004 (Build 19041)
- [ ] Windows 10 20H2 (Build 19042)
- [ ] Windows 10 21H1 (Build 19043)
- [ ] Windows 11 21H2 (Build 22000)
- [ ] Other (specify)
Other Windows Build number
No response
App minimum and target SDK version
- [ ] Windows 10, version 1809 (Build 17763)
- [ ] Windows 10, version 1903 (Build 18362)
- [ ] Windows 10, version 1909 (Build 18363)
- [X] Windows 10, version 2004 (Build 19041)
- [ ] Other (specify)
Other SDK version
No response
Visual Studio Version
2019
Visual Studio Build Number
Version 16.10.1
Device form factor
Desktop
Nuget packages
Microsoft.Toolkit.Uwp.UI.Controls 7.1.2
Additional context
No response
Help us help you
No.
Hello 0xNF, thank you for opening an issue with us!
I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible. Other community members may also look into the issue and provide feedback 🙌
Thanks for reporting this issue @0xNF. Can confirm that this issue is present in 7.1.2 and is reproducible in the current sample app. We'll look into this.
Can also reproduce the issue by using the left arrow key.
It may be caused by trying to set SelectedItems
while the selection mode is None
or Single
as only one or no item can be selected.
Changing this
https://github.com/CommunityToolkit/WindowsCommunityToolkit/blob/a39654ca7e825f459c0b014a46bd9e51de76f169/Microsoft.Toolkit.Uwp.UI.Controls.Input/TokenizingTextBox/TokenizingTextBox.Selection.cs#L220
into
if (SelectionMode == ListViewSelectionMode.Single || SelectionMode == ListViewSelectionMode.None)
{
SelectedItem = Items[currentIndex + increment];
}
else
{
SelectedItems.Add(Items[currentIndex + increment]);
}
does seem to stop it from crashing.
Notice that there are other places that may contain this bug. For example in this case, trying to use shift + arrow key to select multiple items while the selection is none or single will crash the app as well.
https://github.com/CommunityToolkit/WindowsCommunityToolkit/blob/a39654ca7e825f459c0b014a46bd9e51de76f169/Microsoft.Toolkit.Uwp.UI.Controls.Input/TokenizingTextBox/TokenizingTextBox.Selection.cs#L86-L102