WPF textbox throws InvalidOperationException exception: cannot close undo unit because no opened unit exists.

Source: Internet
Author: User

recently encountered a problem. The app uses a sudden crash to view dump discovery exception information such as the following:UI Dispatcher has encountered a problem:Unable to close undo unit. Because there are no open cells.

InAt MS. Internal.Documents.UndoManager.Close (iparentundounit unit, undocloseaction closeaction)At System.Windows.Documents.ImmComposition.UpdateCompositionText (frameworktextcomposition composition, Int32 Resultlength, Boolean Includeresulttext, itextpointer& start, itextpointer& end)
At System.Windows.Documents.ImmComposition.RaiseTextInputStartEvent (frameworktextcomposition composition, Int32 Resultlength, String compositionstring)
At System.Windows.Documents.ImmComposition.OnWmImeChar (IntPtr

From the dump can be seen in the Texttox when the input is suddenly collapsed, may be related to the input method, UndoManager.
Pass~*kbAbility to see stacks of all threadsRetaddr:args to Child:call Site
000007fe ' fd491430:006b0073 ' 00690064 0075006c ' 006f0056 005c0031 ' 0065006d 0064006e ' 00690057:ntdll! Zwwaitformultipleobjects+0xa
00000000 ' 773a0740:00000000 ' 23489cd0 00000000 ' 23489cc0 00000000 ' 00000000 00000000 ' 00000000:kernelbase! Waitformultipleobjectsex+0xe8
000007fe ' eaedc96a:00000000 ' 00000000 000007fe ' d788a580 00000000 ' 1d9f6020 00000000 ' 000018f0:kernel32! Waitformultipleobjects+0xb0
00000000 ' 7742b990:00000000 ' 23489f40 00000000 ' 00000000 00000000 ' 00000001 00000000 ' 2348b120:sogoupy+0x41a614
00000000 ' 77592a4f:00000000 ' 23489f40 00000000 ' 00000006 0000f67a ' 00000000 00000000 ' 00000001:kernel32! unhandledexceptionfilter+0x160
00000000 ' 774fd863:000007fe ' d2640000 000007fe ' f7d9e336 00000000 ' 23490000 00000000 ' 774fd8f5:ntdll! ldrplogfatalusercallbackexception+0x3f
00000000 ' 774d905d:00000000 ' 23490000 00000000 ' 2348a0f8 00000000 ' 2348a080 00000000 ' 2348a100:ntdll! kiusercallbackdispatcherhandler+0x20
00000000 ' 774c8c0f:00000000 ' 23490000 00000000 ' 77326388 000056fa ' 00012a98 00000000 ' 2348dfe0:ntdll! Rtlpexecutehandlerforexception+0xd
00000000 ' 774c9208:00000000 ' 2348b120 00000000 ' 2348aaf0 00000000 ' 00000001 00000000 ' 00000000:ntdll! rtldispatchexception+0x45a
000007fe ' fd49b3dd:00000000 ' 2348b258 00000000 ' 00000001 00000000 ' 00000005 00000000 ' 042b2c00:ntdll! rtlraiseexception+0x22f
000007fe ' f7bc565b:00000000 ' 2348b258 00000000 ' 2348b198 00000000 ' 050ac370 00000000 ' 050bd478:kernelbase! raiseexception+0x39
000007fe ' f7ad18e7:00000000 ' 042cfe08 00000000 ' 050ac370 000007fe ' D2ad5b05 00000000 ' 005946b8:clr! raisetheexceptioninternalonly+0x28b
000007fe ' d2ad5b40:000007fe ' D26b1fe8 00000000 ' 000000ab 00000000 ' 005946b8 00000000 ' 2348b900:clr! Il_rethrow+0x98
000007fe ' f7bc6635:00000000 ' 228c1b10 000007fe ' D26b1fe8 00000000 ' 00594620 00000000 ' 228C1B10:WINDOWSBASE_NI+0X495B40
000007fe ' f7bc6d6c:00000000 ' 00594620 000007fe ' D2ad5b05 00000000 ' 2348dfe0 00000000 ' 005946b8:clr! Exceptiontracker::callhandler+0xc5
000007fe ' f7bc6c1f:00000000 ' 2348dfe0 00000000 ' 2348b740 00000000 ' 2348d430 00000000 ' 00000002:clr! exceptiontracker::callcatchhandler+0x78
00000000 ' 774d90dd:00000000 ' 2348d500 00000000 ' 2348dfe0 00000000 ' 00000000 00000000 ' 2348b740:clr! Processclrexception+0x2e2
From the above dump information can be seen at that time may be used to Sogou input method.
The next step is to analyze which character was entered at that time, or to view all of the stack information at that time through!DSO.0:012>~12e!dso
OS Thread id:0x2080 (12)
Rsp/reg Object Name
000000002142ad48 0000000002c94188 System.Text.UTF8Encoding
000000002142aee0 00000000031de548 System.Windows.Threading.Dispatcher
000000002142AFF0 00000000031de880 System.Windows.Threading.DispatcherUnhandledExceptionEventArgs
000000002142b660 00000000031de548 System.Windows.Threading.Dispatcher
000000002142b678 00000000035b19b8 System.Windows.Threading.DispatcherOperationCallback
000000002142b680 00000000031dee38 MS. Win32.hwndsubclass+dispatcheroperationcallbackparameter
000000002142b6b0 00000000035b19b8 System.Windows.Threading.DispatcherOperationCallback
000000002142b6b8 00000000031de548 System.Windows.Threading.Dispatcher
000000002142b888 0000000002cd1ad0 System.runtimetype
000000002142b980 00000000031de548 System.Windows.Threading.Dispatcher
000000002142b998 00000000035b19b8 System.Windows.Threading.DispatcherOperationCallback
000000002142b9a0 00000000031dee38 MS. Win32.hwndsubclass+dispatcheroperationcallbackparameter
000000002142b9d0 00000000035b19b8 System.Windows.Threading.DispatcherOperationCallback
000000002142b9d8 00000000031de548 System.Windows.Threading.Dispatcher
000000002142bbb0 00000000035b19b8 System.Windows.Threading.DispatcherOperationCallback
000000002142bbc8 00000000035b19b8 System.Windows.Threading.DispatcherOperationCallback
000000002142bbd0 00000000031dee38 MS. Win32.hwndsubclass+dispatcheroperationcallbackparameter
000000002142BC00 00000000035b19b8 System.Windows.Threading.DispatcherOperationCallback
000000002142BC08 00000000031de548 System.Windows.Threading.Dispatcher
000000002142c148 0000000002cd1ad0 System.runtimetype
000000002142c280 00000000031de548 System.Windows.Threading.Dispatcher
000000002142c298 00000000035b19b8 System.Windows.Threading.DispatcherOperationCallback
000000002142c2a0 00000000031dee38 MS. Win32.hwndsubclass+dispatcheroperationcallbackparameter
000000002142c2d0 00000000035b19b8 System.Windows.Threading.DispatcherOperationCallback
000000002142c2d8 00000000031de548 System.Windows.Threading.Dispatcher
000000002142c658 0000000002cd1ad0 System.runtimetype
000000002142cb28 0000000002cd1ad0 System.runtimetype
000000002142cf08 000000000366af28 System.Windows.Documents.TextSelection
000000002142CF10 000000000366acb8 System.Windows.Documents.TextContainer
000000002142d058 0000000002c8ddc8 System.String zh-cn
000000002142d078 00000000032B4D70 system.char[]
000000002142d578 000000000366ad68 System.Windows.Documents.TextEditor
000000002142d5a0 000000000366af28 System.Windows.Documents.TextSelection
000000002142d5c8 000000000366ad68 System.Windows.Documents.TextEditor
000000002142D5E0 00000000030ee118 System.Windows.Input.InputManager
000000002142d608 000000000378e350 System.Windows.Documents.ImmComposition
000000002142d630 000000000378e350 System.Windows.Documents.ImmComposition
000000002142d640 000000000378e350 System.Windows.Documents.ImmComposition
000000002142d668 000000000510f550 System.Windows.Documents.FrameworkTextComposition
000000002142d680 000000000510f530 System.String,
From the above dump information can be seen when the string has ZH-CN and ". ”。 To be able to predict that it should be input method at that time was entered in the Chinese input state. ", causing the textbox to crash.
Conclusion:Through the above information to try to reproduce in the application, found finally the reason is: first switch to English input method. Enter the characters into the textbox to the maximum length, then switch the input to the Chinese input method, select the Sogou IME, then type the letters, then press ",". Hung off.

The push is that the textbox has reached its maximum length. For Sogou input method in the Chinese case "," is to enter or confirm the meaning, and then the IME throws these characters to the control, the control due to the maximum length of the trigger undo.
Workaround: Set the TextBox's Undolimit to 0, or isundoenabled to false, both of which can disable the undo feature to avoid the above exception.



WPF textbox throws InvalidOperationException exception: cannot close undo unit because no opened unit exists.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.