dotnet / wpf

WPF is a .NET Core UI framework for building Windows desktop applications.
MIT License
7.05k stars 1.17k forks source link

WPF in .net core 6.0 or 8.0, process terminated error occured and exit program unexpectly when type korean(IME) character fast in DataGrid. #9829

Open vsfeedback opened 1 week ago

vsfeedback commented 1 week ago

This issue has been moved from a ticket on Developer Community.


[severity:I'm unable to use this version] WpfApp1.zip

instruction

there is very simple code, a sample of datagrid and databinding.

quickly enter Korean while switching cells in datagrid, a 'process terminated' error occurs.

I already post this issue in microsoft learn, but I think o this is lowlevel problem between WPF framework and IME.

Currently, datagrid must be used for development, and the program is easily terminated, which is a problem.

how to reproduce

  1. With the Korean IME running, enter any number of Korean characters (any character does not matter) into a cell of the datagrid.

  2. Click another cell and enter Korean again.

  3. If an error does not occur, repeat the above actions.

environments

tested on 3 PC.

occured OS : window 11 home, professional

occured .net version : 6.0.16, 8.0

error message

Application: WpfApp1.exe

CoreCLR Version: 6.0.1623.17311

.NET Version: 6.0.16

Description: The application requested process termination through System.Environment.FailFast(string message).

Message: 복구할 수 없는 시스템 오류입니다.

Stack:

at System.Environment.FailFast(System.String)

at System.Windows.Documents.TextStore.VerifyTextStoreConsistency()

at System.Windows.Documents.TextStore.GrantLock()

at System.Windows.Documents.TextStore.GrantLockWorker(LockFlags)

at System.Windows.Documents.TextStore.RequestLock(LockFlags, Int32 ByRef)

at MS. Win32.UnsafeNativeMethods+ITextStoreACPSink.OnSelectionChange()

at MS. Win32.UnsafeNativeMethods+ITextStoreACPSink.OnSelectionChange()

at System.Windows.Documents.TextStore.OnSelectionChanged()

at System.Windows.Documents.TextSelection.System.Windows.Documents.ITextRange.NotifyChanged(Boolean, Boolean)

at System.Windows.Documents.TextRangeBase.EndChange(System.Windows.Documents.ITextRange, Boolean, Boolean)

at System.Windows.Documents.TextRange.System.Windows.Documents.ITextRange.EndChange(Boolean, Boolean)

at System.Windows.Documents.TextRange+ChangeBlock.System.IDisposable.Dispose()

at System.Windows.Documents.TextEditorTyping.DoTextInput(System.Windows.Documents.TextEditor, System.String, Boolean, Boolean)

at System.Windows.Documents.TextEditorTyping+TextInputItem.Do()

at System.Windows.Documents.TextEditorTyping.ScheduleInput(System.Windows.Documents.TextEditor, InputItem)

at System.Windows.Documents.TextEditorTyping.OnTextInput(System.Object, System.Windows.Input.TextCompositionEventArgs)

at System.Windows.Controls.Primitives.TextBoxBase.OnTextInput(System.Windows.Input.TextCompositionEventArgs)

at System.Windows.UIElement.OnTextInputThunk(System.Object, System.Windows.Input.TextCompositionEventArgs)

at System.Windows.Input.TextCompositionEventArgs.InvokeEventHandler(System.Delegate, System.Object)

at System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate, System.Object)

at System.Windows.EventRoute.InvokeHandlersImpl(System.Object, System.Windows.RoutedEventArgs, Boolean)

at System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject, System.Windows.RoutedEventArgs)

at System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs)

at System.Windows.Input.InputManager.ProcessStagingArea()

at System.Windows.Input.TextCompositionManager.UnsafeCompleteComposition(System.Windows.Input.TextComposition)

at System.Windows.Input.DefaultTextStore.OnTransitoryExtensionUpdated(ITfContext, Int32, ITfRange, ITfRange, Boolean ByRef)

at MS. Win32.UnsafeNativeMethods+ITfThreadMgr.SetFocus(ITfDocumentMgr)

at MS. Win32.UnsafeNativeMethods+ITfThreadMgr.SetFocus(ITfDocumentMgr)

at System.Windows.Documents.TextStore.OnGotFocus()

at System.Windows.Documents.TextServicesHost._RegisterTextStore(System.Windows.Documents.TextStore)

at System.Windows.Documents.TextStore.OnAttach()

at System.Windows.Documents.TextEditor.InitTextStore(System.Object)

at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)

at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)

at System.Windows.Threading.DispatcherOperation.InvokeImpl()

at MS. Internal.CulturePreservingExecutionContext.CallbackWrapper(System.Object)

at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)

at MS. Internal.CulturePreservingExecutionContext.Run(MS. Internal.CulturePreservingExecutionContext, System.Threading.ContextCallback, System.Object)

at System.Windows.Threading.DispatcherOperation.Invoke()

at System.Windows.Threading.Dispatcher.ProcessQueue()

at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)

at MS. Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)

at MS. Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)

at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)

at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)

at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)

at MS. Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)

at MS. Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)

at MS. Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)

at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)

at System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame)

at System.Windows.Threading.DispatcherOperation.Wait(System.TimeSpan)

at System.Windows.Threading.Dispatcher.InvokeImpl(System.Windows.Threading.DispatcherOperation, System.Threading.CancellationToken, System.TimeSpan)

at System.Windows.Threading.Dispatcher.Invoke(System.Action, System.Windows.Threading.DispatcherPriority, System.Threading.CancellationToken, System.TimeSpan)

at System.Windows.Threading.Dispatcher.Invoke(System.Action, System.Windows.Threading.DispatcherPriority)

at System.Windows.Controls.DataGridTextColumn.OnInput(System.Windows.Input.InputEventArgs)

at System.Windows.Controls.DataGridCell.OnPreviewKeyDown(System.Windows.Input.KeyEventArgs)

at System.Windows.UIElement.OnPreviewKeyDownThunk(System.Object, System.Windows.Input.KeyEventArgs)

at System.Windows.Input.KeyEventArgs.InvokeEventHandler(System.Delegate, System.Object)

at System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate, System.Object)

at System.Windows.EventRoute.InvokeHandlersImpl(System.Object, System.Windows.RoutedEventArgs, Boolean)

at System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject, System.Windows.RoutedEventArgs)

at System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs)

at System.Windows.Input.InputManager.ProcessStagingArea()

at System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport)

at System.Windows.Interop.HwndKeyboardInputProvider.ReportInput(IntPtr, System.Windows.Input.InputMode, Int32, System.Windows.Input.RawKeyboardActions, Int32, Boolean, Boolean, Int32)

at System.Windows.Interop.HwndKeyboardInputProvider.ProcessKeyAction(System.Windows.Interop.MSG ByRef, Boolean ByRef)

at System.Windows.Interop.HwndSource.CriticalTranslateAccelerator(System.Windows.Interop.MSG ByRef, System.Windows.Input.ModifierKeys)

at System.Windows.Interop.HwndSource.OnPreprocessMessage(System.Object)

at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)

at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)

at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)

at System.Windows.Interop.HwndSource.OnPreprocessMessageThunk(System.Windows.Interop.MSG ByRef, Boolean ByRef)

at System.Windows.Interop.ComponentDispatcherThread.RaiseThreadMessage(System.Windows.Interop.MSG ByRef)

at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)

at System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame)

at System.Windows.Threading.Dispatcher.Run()

at System.Windows.Application.RunDispatcher(System.Object)

at System.Windows.Application.RunInternal(System.Windows.Window)

at System.Windows.Application.Run()

at WpfApp1.App.Main()

Original Comments

Feedback Bot on 23/9/2024, 07:51 AM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

miloush commented 1 week ago

I cannot reproduce this with either of the Korean IMEs. What is your Windows build? Can you share a screen recording?

miloush commented 1 week ago

Does it repro on net48?

relay955 commented 1 week ago

thanks for your interest, there is my windows build information. I currently installed recently updates all. asdf

but I found occuring error on another windows 11 home PC also, that PC is update recently too.

to reproduce this error, when activate cell into edit mode, type more than two Korean characters quickly with almost no delay.

Below is a video showing an example of the error occurring with visual studio community 2022

https://github.com/user-attachments/assets/51cc97a2-e1e2-43ba-87a6-69d5bd3e01b0

This can easily reproduce if the delay between the cell switching to edit mode and entering Korean is short.

However, in this example, an error occurs only if type very quickly, but in a heavy datagrid with complex code, an error occurs even if type a little quickly.

to quickly enter data in a cell, most users often press Enter and then quickly fill in the data to the next row.

I tried test with .net 6.0 and 8.0 both, but error not disappear.

in .net framework 4.8, error message is slightly different, but stacktrace is similar with other version tests.

image

miloush commented 1 week ago

Thank you! Right, so by starting to type fast into a cell that is not in edit mode I can sometimes reproduce.

Possibly same issue as in #3315.

miloush commented 1 week ago

This is duplicate of #9805 but there is more useful information here.

indigoray commented 1 week ago

The last reason the exception occurs...

private void VerifyTextStoreConsistency()
{
    if (_netCharCount != TextContainer.IMECharCount)
    {
        Invariant.Assert(condition: false, "TextContainer/TextStore have inconsistent char counts!");
    }
}
indigoray commented 1 week ago

Similar Issue

https://github.com/dotnet/wpf/pull/4985

miloush commented 1 week ago

It's not a problem to find the assert that crashes it, it's finding out why the assert fails.

indigoray commented 1 week ago

Based on my investigation into the exception call stack trace, it appears that this issue occurs during the OnAttach process of the TextStore. If rapid input is provided to the IME during _textservicesHost.RegisterTextStore(this) before the following line is executed: TextContainer.Change += OnTextContainerChange; other update interactions are sent to the TextStore, resulting in an inconsistency during the ConsistencyCheck.

internal void OnAttach() { _netCharCount = TextContainer.IMECharCount; _textservicesHost = TextServicesHost.Current; _textservicesHost.RegisterTextStore(this); //the exception occurs during this is being executied TextContainer.Change += OnTextContainerChange; //before this line _textservicesproperty = new TextServicesProperty(this); if (IMECompositionTracer.IsEnabled) { IMECompositionTracer.ConfigureTracing(this); } }

In other words, the issue arises when interactions begin while only the registration has occurred, before the event handler that synchronizes changes in the TextContainer with the TextStore is connected.

here is the full call stack

WindowsBase.dll!MS.Internal.Invariant.FailFast(string message, string detailMessage)    Unknown

PresentationFramework.dll!System.Windows.Documents.TextStore.VerifyTextStoreConsistency() Line 2936 C# PresentationFramework.dll!System.Windows.Documents.TextStore.GrantLock() Line 2397 C# PresentationFramework.dll!System.Windows.Documents.TextStore.GrantLockWorker(MS.Win32.UnsafeNativeMethods.LockFlags flags) Line 2347 C# PresentationFramework.dll!System.Windows.Documents.TextStore.RequestLock(MS.Win32.UnsafeNativeMethods.LockFlags flags, out int hrSession) Line 1155 C# [Native to Managed Transition]
TextInputFramework.dll!CACPWrap::RequestLock(unsigned long,long ) Unknown TextInputFramework.dll!SafeRequestLock(struct ITextStoreAnchor ,unsigned long,long ) Unknown TextInputFramework.dll!CInputContext::_OnSelectionChangeInternal(int) Unknown TextInputFramework.dll!CInputContext::OnSelectionChange(void) Unknown TextInputFramework.dll!CACPWrap::OnSelectionChange(void) Unknown [Managed to Native Transition]
PresentationFramework.dll!System.Windows.Documents.TextStore.OnSelectionChanged() Line 2021 C# PresentationFramework.dll!System.Windows.Documents.TextSelection.System.Windows.Documents.ITextRange.NotifyChanged(bool disableScroll, bool skipEvents) Line 301 C# PresentationFramework.dll!System.Windows.Documents.TextRangeBase.EndChange(System.Windows.Documents.ITextRange thisRange, bool disableScroll, bool skipEvents) Line 335 C# PresentationFramework.dll!System.Windows.Documents.TextRange.System.Windows.Documents.ITextRange.EndChange(bool disableScroll, bool skipEvents) Line 365 C# PresentationFramework.dll!System.Windows.Documents.TextRange.ChangeBlock.System.IDisposable.Dispose() Line 30 C# PresentationFramework.dll!System.Windows.Documents.TextEditorTyping.DoTextInput(System.Windows.Documents.TextEditor This, string textData, bool isInsertKeyToggled, bool acceptControlCharacters) Line 971 C# PresentationFramework.dll!System.Windows.Documents.TextEditorTyping.TextInputItem.Do() Line 50 C# PresentationFramework.dll!System.Windows.Documents.TextEditorTyping.ScheduleInput(System.Windows.Documents.TextEditor This, System.Windows.Documents.TextEditorTyping.InputItem item) Line 984 C# PresentationFramework.dll!System.Windows.Documents.TextEditorTyping.OnTextInput(object sender, System.Windows.Input.TextCompositionEventArgs e) Line 278 C# PresentationFramework.dll!System.Windows.Controls.Primitives.TextBoxBase.OnTextInput(System.Windows.Input.TextCompositionEventArgs e) Line 881 C# PresentationCore.dll!System.Windows.UIElement.OnTextInputThunk(object sender, System.Windows.Input.TextCompositionEventArgs e) 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.RoutedEventHandlerInfo.InvokeHandler(object target, System.Windows.RoutedEventArgs routedEventArgs) 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.UIElement.RaiseEvent(System.Windows.RoutedEventArgs args, bool trusted) Unknown PresentationCore.dll!System.Windows.Input.InputManager.ProcessStagingArea() Unknown PresentationCore.dll!System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs input) Unknown PresentationCore.dll!System.Windows.Input.TextCompositionManager.UnsafeCompleteComposition(System.Windows.Input.TextComposition composition) Unknown PresentationCore.dll!System.Windows.Input.DefaultTextStore.OnTransitoryExtensionUpdated(MS.Win32.UnsafeNativeMethods.ITfContext context, int ecReadOnly, MS.Win32.UnsafeNativeMethods.ITfRange rangeResult, MS.Win32.UnsafeNativeMethods.ITfRange rangeComposition, out bool fDeleteResultRange) Unknown [Native to Managed Transition]
TextInputFramework.dll!CDocumentInputManager::OnTransitoryExtensionUpdated(struct ITfContext
,unsigned long,struct ITfRange ,struct ITfRange ,int ) Unknown msctf.dll!CTransitoryExtension::CallUpdatedSink(unsigned long) Unknown msctf.dll!CTransitoryExtension::OnEndEdit(struct ITfContext ,unsigned long,struct ITfEditRecord ) Unknown TextInputFramework.dll!CInputContext::_NotifyEndEdit(void) Unknown TextInputFramework.dll!CInputContext::_PseudoSyncEditSessionQiCallback(class CInputContext ,struct _TS_QUEUE_ITEM ,enum QiCallbackCode) Unknown TextInputFramework.dll!CInputContext::_DispatchQueueItem(struct _TS_QUEUE_ITEM ) Unknown TextInputFramework.dll!CInputContext::_EmptyLockQueue(unsigned long,int) Unknown TextInputFramework.dll!CInputContext::OnLockGranted(unsigned long) Unknown TextInputFramework.dll!CACPWrap::OnLockGranted(unsigned long) Unknown msctf.dll!CTextStoreImpl::RequestLock() Unknown TextInputFramework.dll!CACPWrap::RequestLock(unsigned long,long ) Unknown TextInputFramework.dll!SafeRequestLock(struct ITextStoreAnchor ,unsigned long,long ) Unknown TextInputFramework.dll!CInputContext::_QueueItem(struct _TS_QUEUE_ITEM ,int,long ) Unknown TextInputFramework.dll!CInputContext::TerminateComposition(struct ITfCompositionView ) Unknown TextInputFramework.dll!CInputContext::FinalizeComposition(unsigned long) Unknown msctf.dll!CThreadInputMgr::_SetFocus(struct IDocumentInputManagerPrivate ,int) Unknown msctf.dll!CThreadInputMgr::SetFocus(struct ITfDocumentMgr ) Unknown [Managed to Native Transition]
PresentationFramework.dll!System.Windows.Documents.TextStore.OnGotFocus() Line 1964 C# PresentationFramework.dll!System.Windows.Documents.TextServicesHost._RegisterTextStore(System.Windows.Documents.TextStore textstore) Line 231 C# PresentationFramework.dll!System.Windows.Documents.TextStore.OnAttach() Line 1936 C# PresentationFramework.dll!System.Windows.Documents.TextEditor.InitTextStore(object o) Line 1063 C# 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.DispatcherOperation.InvokeImpl() Unknown WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(object state) Unknown WindowsBase.dll!MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(object obj) Unknown mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Line 516 C# mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Line 487 C# mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 480 C# WindowsBase.dll!MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Unknown WindowsBase.dll!System.Windows.Threading.DispatcherOperation.Invoke() Unknown WindowsBase.dll!System.Windows.Threading.Dispatcher.ProcessQueue() Unknown WindowsBase.dll!System.Windows.Threading.Dispatcher.WndProcHook(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) Unknown WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) Unknown WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o) Unknown

indigoray commented 1 week ago

For the time being, this is my workaround : This code makes time for the TextStore OnAttach to finish without being interrupted


  private void radGridView_PreparingCellForEdit(object sender, GridViewPreparingCellForEditEventArgs e)
        {

            if (e.EditingElement is TextBox textBox)
            {

                textBox.IsEnabled = false;
                textBox.InvalidateVisual();

                DispatcherTimer timer = new DispatcherTimer();
                timer.Interval = TimeSpan.FromMilliseconds(20);
                timer.Tick += (s, args) =>
                {
                    timer.Stop();
                    textBox.IsEnabled = true;
                    textBox.Focus();
                };
                timer.Start();
            }
        }
akon47 commented 1 week ago

This issue is also reproduced in visual studio. Solution Explorer > focus to any file or directory > F2 key down(rename) and fast input korean.

https://github.com/user-attachments/assets/ca7d6061-87bd-4cee-a7a7-b2f7b9916ec8