背景介绍:
.Net项目引用了一个VB写的COM组件,在.Net中实现了COM组件一个事件的处理。调试时,事件处理方法没有出错,事件处理文法一结束,就出了以下错误。请大家帮忙解答一下,非常感谢!
异常日志:
System.AccessViolationException was unhandled
Message="Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
Source="System.Windows.Forms"
StackTrace:
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageA(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at TT.Client.TestApp.Program.Main() in E:\WorkSpace\TT\TT.TestApp\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
这是你的COM 组件内部有bug,访问内存越界了,很可能是函数在堆栈中的返回指针被冲掉了,所以函数调用结束后会出错。
试下 设置 VS :
工具-> 选项->调试->找到“在模块加载时取消 JIT 优化(仅限托管)”这项 不勾选; 确定,如下图:
不勾选下图 红色标记的选项:
你在VB中能正常调用你的COM组件的事件吗?