VS2010代码编辑窗口第一次编辑操作导致报错的问题

用VS2010打开一个C/C++项目,随便选个源代码文件,编辑,报错提示遇到异常,可能由于某Add-in导致等blah blah blah…,确定无视提示后继续编辑,写完一个函数的proto后IDE卡死,稍候直接大红叉异常,只能强制结束进程。

开始按照提示信息,怀疑是VM Ware的Virtual Debugger插件导致,于是花了一会时间把插件以正常添加/删除方式卸载掉,重启IDE,错误依旧,发现被M$的提示信息误导了!

用VS的命令行方式挂log参数启动,devenv /log,触发错误提示后查看ActivityLog.xml日志,xsl顺利的解析出了2条大红色的错误信息:

System.InvalidCastException: Unable to cast COM object of type ‘System.__ComObject’ to interface type ‘Microsoft.VisualStudio.TextManager.Interop.IVsTextReplaceEvents’. This operation failed because the QueryInterface call on the COM component for the interface with IID ‘{CF9928D9-65AE-4319-A446-94ED5C45ECDE}’ failed due to the following error: 不支持此接口 (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)). at System.StubHelpers.StubHelpers.GetCOMIPFromRCW(Object objSrc, IntPtr pCPCMD, Boolean& pfNeedsRelease) at Microsoft.VisualStudio.TextManager.Interop.IVsTextReplaceEvents.OnReplace(ChangeInput[] pCI) at Microsoft.VisualStudio.Editor.Implementation.VsTextBufferAdapter.OnTextBufferChangedHighPriority(Object sender, TextContentChangedEventArgs e) at Microsoft.VisualStudio.Text.Utilities.GuardedOperations.RaiseEvent[TArgs](Object sender, EventHandler`1 eventHandlers, TArgs args)

 

System.InvalidCastException: Unable to cast COM object of type ‘System.__ComObject’ to interface type ‘Microsoft.VisualStudio.Editor.Implementation.IVsTextStreamEvents_Private’. This operation failed because the QueryInterface call on the COM component for the interface with IID ‘{96FC7D44-BCDD-4F00-AE4D-07E26B2C0E52}’ failed due to the following error: 不支持此接口 (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)). at System.StubHelpers.StubHelpers.GetCOMIPFromRCW(Object objSrc, IntPtr pCPCMD, Boolean& pfNeedsRelease) at Microsoft.VisualStudio.Editor.Implementation.IVsTextStreamEvents_Private.OnChangeStreamText(Int32 iPos, Int32 iOldLen, Int32 iNewLen, Int32 fLast) at Microsoft.VisualStudio.Editor.Implementation.VsTextBufferAdapter.OnTextBufferChanged(Object sender, TextContentChangedEventArgs e) at Microsoft.VisualStudio.Text.Utilities.GuardedOperations.RaiseEvent[TArgs](Object sender, EventHandler`1 eventHandlers, TArgs args)

有了具体错误信息,发现是某个VS编辑COM控件的注册信息丢失导致,最后还算轻松的找到了解决方法:

用注册表编辑器regedit按系统类型进入以下位置

32-Bit Windows: [HKEY_CLASSES_ROOT\CLSID\{73B7DC00-F498-4ABD-AB79-D07AFD52F395}\InProcServer32]

64-Bit Windows: [HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{73B7DC00-F498-4ABD-AB79-D07AFD52F395}\InProcServer32]

补全此项的默认键值
32-Bit Windows: "C:\Program Files\Common Files\Microsoft Shared\MSEnv\TextMgrP.dll"
64-Bit Windows: "C:\Program Files (x86)\Common Files\Microsoft Shared\MSEnv\TextMgrP.dll"

再次启动,错误消失。

参考链接:

http://stackoverflow.com/questions/4791519/visual-studio-crash-when-typing-in-editor

博主友情提示:

如您在评论中需要提及如QQ号、电子邮件地址或其他隐私敏感信息,欢迎使用>>博主专用加密工具v3<<处理后发布,原文只有博主可以看到。