ExecutionEngineException when calling TextBox.Focus in TextInputStart
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
* .NET Core Version: 5.0.0-preview.7.20364.11
* Windows version:
Build 10.0.19041.388
Windows feature experience pack 120.2202.130.0
* Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes
* Is this bug related specifically to tooling in Visual Studio (e.g. XAML Designer, Code editing, etc...)?
No
* Security issues and bugs should be reported privately, learn more via our [responsible disclosure guidelines](https://github.com/dotnet/wpf/blob/master/README.md#reporting-security-issues-and-security-bugs).
**Problem description:**
When using Microsoft Japanese IME, `TextBox.Focus` throws `ExecutionEngineException` when calling it in a `TextInputStart` attached event handler.
**Actual behavior:**
```
System.ExecutionEngineException
HResult is 80131506
> WindowsBase.dll!MS.Internal.Invariant.FailFast(string message, string detailMessage) Unknown
PresentationFramework.dll!System.Windows.Documents.TextStore.VerifyTextStoreConsistency() Unknown
PresentationFramework.dll!System.Windows.Documents.TextStore.GrantLock() Unknown
PresentationFramework.dll!System.Windows.Documents.TextStore.GrantLockWorker(MS.Win32.UnsafeNativeMethods.LockFlags flags) Unknown
PresentationFramework.dll!System.Windows.Documents.TextStore.RequestLock(MS.Win32.UnsafeNativeMethods.LockFlags flags, out int hrSession) Unknown
[Native to Managed Transition]
[Managed to Native Transition]
PresentationFramework.dll!System.Windows.Documents.FrameworkTextComposition.CompleteCurrentComposition(MS.Win32.UnsafeNativeMethods.ITfDocumentMgr documentMgr) Unknown
PresentationFramework.dll!System.Windows.Documents.TextStore.CompleteComposition() Unknown
PresentationFramework.dll!System.Windows.Documents.TextEditor.OnLostKeyboardFocus(object sender, System.Windows.Input.KeyboardFocusChangedEventArgs e) Unknown
PresentationFramework.dll!System.Windows.Controls.Primitives.TextBoxBase.OnLostKeyboardFocus(System.Windows.Input.KeyboardFocusChangedEventArgs e) Unknown
PresentationCore.dll!System.Windows.UIElement.OnLostKeyboardFocusThunk(object sender, System.Windows.Input.KeyboardFocusChangedEventArgs e) Unknown
PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate handler, object target) Unknown
PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source, System.Windows.RoutedEventArgs args, bool reRaised) Unknown
PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject sender, System.Windows.RoutedEventArgs args) Unknown
PresentationCore.dll!System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs args) Unknown
PresentationCore.dll!System.Windows.Input.InputManager.ProcessStagingArea() Unknown
PresentationCore.dll!System.Windows.Input.KeyboardDevice.ChangeFocus(System.Windows.DependencyObject focus, int timestamp) Unknown
PresentationCore.dll!System.Windows.Input.KeyboardDevice.TryChangeFocus(System.Windows.DependencyObject newFocus, System.Windows.Input.IKeyboardInputProvider keyboardInputProvider, bool askOld, bool askNew, bool forceToNullIfFailed) Unknown
PresentationCore.dll!System.Windows.Input.KeyboardDevice.Focus(System.Windows.DependencyObject focus, bool askOld, bool askNew, bool forceToNullIfFailed) Unknown
PresentationCore.dll!System.Windows.Input.KeyboardDevice.Focus(System.Windows.IInputElement element) Unknown
PresentationCore.dll!System.Windows.UIElement.Focus() Unknown
PresentationCore.dll!System.Windows.Input.TextCompositionEventArgs.InvokeEventHandler(System.Delegate genericHandler, object genericTarget) Unknown
PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate handler, object target) Unknown
PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source, System.Windows.RoutedEventArgs args, bool reRaised) Unknown
PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject sender, System.Windows.RoutedEventArgs args) Unknown
PresentationCore.dll!System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs args) Unknown
PresentationCore.dll!System.Windows.Input.InputManager.ProcessStagingArea() Unknown
PresentationCore.dll!System.Windows.Input.TextCompositionManager.UnsafeStartComposition(System.Windows.Input.TextComposition composition) Unknown
PresentationCore.dll!System.Windows.Input.TextCompositionManager.StartComposition(System.Windows.Input.TextComposition composition) Unknown
PresentationFramework.dll!System.Windows.Documents.TextStore.RaiseCompositionEvents(out int appSelectionAnchorOffset, out int appSelectionMovingOffset) Unknown
PresentationFramework.dll!System.Windows.Documents.TextStore.HandleCompositionEvents(int previousUndoCount) Unknown
PresentationFramework.dll!System.Windows.Documents.TextStore.GrantLockWorker(MS.Win32.UnsafeNativeMethods.LockFlags flags) Unknown
PresentationFramework.dll!System.Windows.Documents.TextStore.RequestLock(MS.Win32.UnsafeNativeMethods.LockFlags flags, out int hrSession) Unknown
[Native to Managed Transition]
[Managed to Native Transition]
PresentationCore.dll!System.Windows.Input.TextServicesContext.Keystroke(int wParam, int lParam, System.Windows.Input.TextServicesContext.KeyOp op) Unknown
PresentationCore.dll!System.Windows.Input.TextServicesManager.TextServicesKeystroke(System.Windows.Input.TextServicesContext context, System.Windows.Input.KeyEventArgs keyArgs, bool test) Unknown
PresentationCore.dll!System.Windows.Input.TextServicesManager.PostProcessInput(object sender, System.Windows.Input.ProcessInputEventArgs e) Unknown
PresentationCore.dll!System.Windows.Input.InputManager.RaiseProcessInputEventHandlers(System.Windows.Input.ProcessInputEventHandler postProcessInput, System.Windows.Input.ProcessInputEventArgs processInputEventArgs) Unknown
PresentationCore.dll!System.Windows.Input.InputManager.ProcessStagingArea() Unknown
PresentationCore.dll!System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport inputReport) Unknown
PresentationCore.dll!System.Windows.Interop.HwndKeyboardInputProvider.ReportInput(System.IntPtr hwnd, System.Windows.Input.InputMode mode, int timestamp, System.Windows.Input.RawKeyboardActions actions, int scanCode, bool isExtendedKey, bool isSystemKey, int virtualKey) Unknown
PresentationCore.dll!System.Windows.Interop.HwndKeyboardInputProvider.ProcessKeyAction(ref System.Windows.Interop.MSG msg, ref bool handled) Unknown
PresentationCore.dll!System.Windows.Interop.HwndSource.CriticalTranslateAccelerator(ref System.Windows.Interop.MSG msg, System.Windows.Input.ModifierKeys modifiers) Unknown
PresentationCore.dll!System.Windows.Interop.HwndSource.OnPreprocessMessage(object param) Unknown
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs) Unknown
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) Unknown
WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs) Unknown
PresentationCore.dll!System.Windows.Interop.HwndSource.OnPreprocessMessageThunk(ref System.Windows.Interop.MSG msg, ref bool handled) Unknown
WindowsBase.dll!System.Windows.Interop.ComponentDispatcherThread.RaiseThreadMessage(ref System.Windows.Interop.MSG msg) Unknown
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame) Unknown
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame frame) Unknown
WindowsBase.dll!System.Windows.Threading.Dispatcher.Run() Unknown
PresentationFramework.dll!System.Windows.Application.RunDispatcher(object ignore) Unknown
PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window window) Unknown
PresentationFramework.dll!System.Windows.Application.Run() Unknown
```
**Expected behavior:**
The program should not crash.
**Minimal repro:**
1. Create a new WPF project
```console
dotnet new wpf -lang vb
```
2. Edit `MainWindow.xaml`
```xml
1. Use Windows 10 version 2004 (ja-JP)
2. Click this text box ↓
3. Switch to Japanese IME
4. Switch to Hiragana mode
5. Press "A"
Don't use this one:
```
3. Edit `MainWindow.xaml.vb`
```vbnet
Class MainWindow
Private Sub MainWindow_Loaded() Handles Me.Loaded
TextCompositionManager.AddTextInputStartHandler(Editor1, AddressOf Editor2.Focus)
End Sub
End Class
```
4. Run the project
```console
dotnet run
```
5. Click the first text box.
6. Use Japanese IME, Hiragana mode.
7. Press the "A" key.
Contributor guide
Assessment
This issue has not been assessed yet.