近期遇到一个问题。应用使用过程中突然崩溃,查看dump发现异常信息例如以下:
UI dispatcher has encountered a problem:
无法关闭撤消单元。由于不存在已打开的单元。

   at 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

从dump上能够看到当时是在TextTox进行输入时突然崩溃,可能和输入法、UndoManager有关。
通过~*kb能够看到全部线程的堆栈
RetAddr           : 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
从上面的dump信息能够看到当时有可能是用到搜狗输入法。
接下来我们就是要分析当时输入的是哪个字符,还是通过!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    ,
从上面dump信息能够看出当时的string有zh-cn以及“ 。”。 能够推測当时应该是输入法当时是在中文输入状态下输入了“ 。”, 导致TextBox崩溃。
结论:
通过上述信息试着在应用上进行重现, 发现终于原因是:
先切换到英文输入法。输入字符到TextBox到最大长度,然后切换输入到中文输入法,选择搜狗输入法,然后敲入字母,然后按“,”。挂掉了。

推測是TextBox已经到了最大长度。对于搜狗输入法在中文情况“,”就是回车或者确认的意思,然后IME把这些字符扔给了控件,控件由于到了最大长度就又触发了Undo。
解决的方法:
把TextBox的UndoLimit设置为0,或者IsUndoEnabled设置为False, 两者都能够禁用Undo功能, 从而避免上述异常。

WPF的TextBox抛出InvalidOperationException异常:Cannot close undo unit because no opened unit exists.的更多相关文章

  1. 为什么只有在用Visual Studio启动程序时会抛出InvalidOperationException异常

    博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:为什么只有在用Visual Studio启动程序时会抛出InvalidOperationExceptio ...

  2. 应该抛出什么异常?不应该抛出什么异常?(.NET/C#)

    我在 .NET/C# 建议的异常处理原则 中描述了如何 catch 异常以及重新 throw.然而何时应该 throw 异常,以及应该 throw 什么异常呢? 究竟是谁错了? 代码中从上到下从里到外 ...

  3. 将Controller抛出的异常转到特定View

    <!-- 将Controller抛出的异常转到特定View --> <bean class="org.springframework.web.servlet.handler ...

  4. 使用visual studio 2015调用阿里云oss .net sdk 2.2的putobject接口抛出outofmemory异常

    问题描述: 使用阿里云oss .net sdk 2.2版本,使用putobject接口上传文件时,抛出outofmemory异常. 原因分析: 上传时,用于准备上传的数据缓冲区内存分配失败.与应用软件 ...

  5. 捕获Java线程池执行任务抛出的异常

    捕获Java线程池执行任务抛出的异常Java中线程执行的任务接口java.lang.Runnable 要求不抛出Checked异常, public interface Runnable { publi ...

  6. java 检查抛出的异常是否是要捕获的检查性异常或运行时异常或错误

    /** * Return whether the given throwable is a checked exception: * that is, neither a RuntimeExcepti ...

  7. druid抛出的异常------javax.management.InstanceAlreadyExistsException引发的一系列探索

    最近项目中有个定时任务的需求,定时检查mysql数据与etcd数据的一致性,具体实现细节就不说了,今天要说的就是实现过程中遇到了druid抛出的异常,以及解决的过程 异常 异常详细信息 五月 05, ...

  8. 外部无法捕捉Realm的doGetAuthenticationInfo方法抛出的异常

    shiro权限框架,用户登录方法的subject.login(token)会进入自定义的UserNamePasswordRealm类的doGetAuthenticationInfo身份验证方法 通常情 ...

  9. JavaWeb项目中获取对Oracle操作时抛出的异常错误码

    最近在项目中碰到了这么一个需求,一个JavaWeb项目,数据库用的是Oracle.业务上有一个对一张表的操作功能,当时设置了两个字段联合的唯一约束.由于前断没有对重复字段的校验,需要在插入时如果碰到唯 ...

随机推荐

  1. Python的功能模块[3] -> binascii -> 编码转换

    binascii模块 / binascii Module binascii模块包含很多在二进制和 ASCII 编码的二进制表示之间的转换方法.关于进制转换可以参考一些内置函数. hexlify 与 u ...

  2. 洛谷——P1595 信封问题

    P1595 信封问题 题目描述 某人写了n封信和n个信封,如果所有的信都装错了信封.求所有信都装错信封共有多少种不同情况. 输入输出格式 输入格式: 一个信封数n(n<=20) 输出格式: 一个 ...

  3. django-useren配置

    http://bobbyong.com/blog/step-by-step-guide-on-configuring-django-userena/

  4. 路由器漏洞利用工具RouterSploit

     路由器漏洞利用工具RouterSploit 网络中存在大量的嵌入式设备,如路由器.智能摄像头.这类设备安全防护程度较低.由于这些设备更新不方便,一旦发现漏洞,往往不能及时修复.所以,在网络渗透测试中 ...

  5. C#实现简单的字符串加密

    最近用到一些字符串加密,而.net中提供的加密算法中用起来比较复杂,便简单的封装了一下,方便日后使用.     public class Encrypt    {        static Enco ...

  6. 【spring boot】集成了druid后,同样的mybatis模糊查询语句出错Caused by: com.alibaba.druid.sql.parser.ParserException: syntax error, error in :'name LIKE '%' ? '%'

    druid版本是 <!-- https://mvnrepository.com/artifact/com.alibaba/druid 数据库连接池--> <dependency> ...

  7. 部署步骤“回收 IIS 应用程序池”中出现错误: 无法将通信对象 System.ServiceModel.InstanceContext 用于通信,因为它已经被中止。

    ??? 重启iis应用程序池和网站都不管用,重启vs就好了,一脸懵逼. 有没有更好的方法?

  8. LLVM每日谈之二十 Everything &amp;&amp; Clang driver

    作者:史宁宁(snsn1984) 近期在读<Getting Started with LLVM Core Libraries>.这是读的第一本LLVM的书.非常多地方尽管讲的是自己知道的东 ...

  9. 【Hadoop】Hadoop MR Job工作流引擎

    Apache Oozie 是用于 Hadoop 平台的一种工作流调度引擎.该框架(如图 1 所示)使用 Oozie 协调器促进了相互依赖的重复工作之间的协调,您可以使用预定的时间或数据可用性来触发 A ...

  10. 2017.8.9在虚拟机中安装linux系统

    0 安装前提 已经安装好VM,并且配置好,具体过程参看随笔:2017.8.5 VMware的介绍与安装 相关随笔:2017.8.5 Linux达人养成计划 I 需要知道的概念:VMWare,虚拟机,真 ...