C# 非常模糊的例外
我一直在做一个利用wunderground的AutoCompleteAPI的项目,我一直遇到一个非常随机的错误。代码位于 我得到的异常是AccessViolationException。在文本框中键入时偶尔会出现这种情况 例外信息:C# 非常模糊的例外,c#,.net,xmlreader,C#,.net,Xmlreader,我一直在做一个利用wunderground的AutoCompleteAPI的项目,我一直遇到一个非常随机的错误。代码位于 我得到的异常是AccessViolationException。在文本框中键入时偶尔会出现这种情况 例外信息: using (XmlReader reader = XmlReader.Create(requestURL)) 异常:引发:“指定的注册表项不存在。”(System.IO.IOException) 引发System.IO.IOException:“指定的注册表项不
using (XmlReader reader = XmlReader.Create(requestURL))
异常:引发:“指定的注册表项不存在。”(System.IO.IOException)
引发System.IO.IOException:“指定的注册表项不存在。”
时间:2013-05-1814:55:59
线程:主线程[5672]
异常:捕获:“指定的注册表项不存在。”(System.IO.IOException)
捕获到System.IO.IOException:“指定的注册表项不存在。”
时间:2013-05-1814:55:59
线程:主线程[5672]
Application.Run(新Form1())
异常:抛出:“试图读取或写入受保护的内存。这通常表示其他内存已损坏。”(System.AccessViolationException)
引发System.AccessViolationException:“试图读取或写入受保护的内存。这通常表示其他内存已损坏。”
时间:2013-05-1814:55:59
线程:主线程[5672]
异常:抛出:“试图读取或写入受保护的内存。这通常表示其他内存已损坏。”(System.AccessViolationException)
引发System.AccessViolationException:“试图读取或写入受保护的内存。这通常表示其他内存已损坏。”
时间:2013-05-18 15:00:01
线程:主线程[4340]
我已经在3台不同的电脑上试过了,过了一会儿。。同样的错误总是发生。我可以在Windows 8上重新设置访问冲突。您必须启用非托管代码调试,并启用符号服务器以查看原因,问题制造者是内置于Windows中的自动完成消息处理程序。一般来说,这是一段相当古怪的代码,它是通过对编辑控件进行子类化来实现的,以拦截消息。调用堆栈如下所示:
shell32.dll!CAutoComplete::_StartCompletion() + 0x4e bytes
shell32.dll!CAutoComplete::_OnChar() + 0x7a bytes
shell32.dll!CAutoComplete::_EditWndProc() - 0x6ae52 bytes
shell32.dll!CAutoComplete::s_EditWndProc() + 0x23 bytes
comctl32.dll!_CallNextSubclassProc@20() + 0x92 bytes
comctl32.dll!_MasterSubclassProc@16() + 0xa5 bytes
user32.dll!_InternalCallWinProc@20() + 0x23 bytes
user32.dll!_UserCallWinProcCheckWow@36() + 0xbd bytes
user32.dll!_DispatchMessageWorker@8() + 0xf8 bytes
user32.dll!_DispatchMessageW@4() + 0x10 bytes
[Managed to Native Transition]
System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(System.IntPtr dwComponentID, int reason, int pvLoopData) + 0x24d bytes
// etc.., not interesting
this.BeginInvoke(new Action(() => {
textboxInput.AutoCompleteCustomSource = autoComplete;
}));
这会出错,因为TextChanged事件处理程序中存在TextBox.AutoCompleteCustomSource属性分配。更改该属性会产生大量的副作用,它会强制重新创建编辑控件窗口,以便新的自动完成列表生效。这与子类化代码的交互非常差,可能是因为它仍然使用旧的编辑控件,该控件的窗口在Winforms有机会重新初始化新控件之前被破坏或运行
解决方法是等待设置属性,直到事件处理完成。这可以通过Control.BeginInvoke()方法优雅地完成。将属性指定更改为如下所示:
shell32.dll!CAutoComplete::_StartCompletion() + 0x4e bytes
shell32.dll!CAutoComplete::_OnChar() + 0x7a bytes
shell32.dll!CAutoComplete::_EditWndProc() - 0x6ae52 bytes
shell32.dll!CAutoComplete::s_EditWndProc() + 0x23 bytes
comctl32.dll!_CallNextSubclassProc@20() + 0x92 bytes
comctl32.dll!_MasterSubclassProc@16() + 0xa5 bytes
user32.dll!_InternalCallWinProc@20() + 0x23 bytes
user32.dll!_UserCallWinProcCheckWow@36() + 0xbd bytes
user32.dll!_DispatchMessageWorker@8() + 0xf8 bytes
user32.dll!_DispatchMessageW@4() + 0x10 bytes
[Managed to Native Transition]
System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(System.IntPtr dwComponentID, int reason, int pvLoopData) + 0x24d bytes
// etc.., not interesting
this.BeginInvoke(new Action(() => {
textboxInput.AutoCompleteCustomSource = autoComplete;
}));
现在,文本框的窗口将被销毁,并在稍后重新创建,这样就不会像处理按键按下事件一样破坏窗口。请注意重新创建窗口的效果是如何显而易见的,文本框就像廉价汽车旅馆一样闪烁。我严重怀疑您是否真的想在发货程序中使用此功能。我现在不知道,但如果您能够跟踪并发布异常的堆栈跟踪,可能会有所帮助。这将有助于了解错误发生的确切位置。AccessViolationException通常是您正在使用的非托管组件中的错误。有时,发生此错误是因为您正在执行组件不喜欢的操作,因此可能存在解决方法。最好是联系组件供应商支持。我对您的Repo项目表示敬意。顺便说一句,您使帮助您变得很容易。该项目符合我自己的利益。我想学习如何使用外部API。我猜我想用AutoComplete做的事情通常只适用于本地SQL数据库或类似的东西。谢谢你帮助我!