C# Can';t在C+中处理AccessViolationException+/CLI 我对C++和CLI不太熟悉,但我很久以前就做过C++。我试图调试AccessViolationException我在JSCore项目中的JSContext::EvaluateScript方法的WebKit.NET中。以下是导致异常的代码行: JSValueRef result = NULL; try { result = JSEvaluateScript(_context, jsScript, /*(JSObjectRef)jsObj*/NULL, NULL, 0, &exception); } catch(...) { }

C# Can';t在C+中处理AccessViolationException+/CLI 我对C++和CLI不太熟悉,但我很久以前就做过C++。我试图调试AccessViolationException我在JSCore项目中的JSContext::EvaluateScript方法的WebKit.NET中。以下是导致异常的代码行: JSValueRef result = NULL; try { result = JSEvaluateScript(_context, jsScript, /*(JSObjectRef)jsObj*/NULL, NULL, 0, &exception); } catch(...) { },c#,webkit,interop,c++-cli,access-violation,C#,Webkit,Interop,C++ Cli,Access Violation,此错误将随机发生。我知道\u context和jsScript不为空。奇怪的是,当错误发生时,Program.cs文件打开,异常出现在Application.Run(new Form1())上行带有一个targetingException,但我可以在IntelliTrace中看到,就在这之前,在上面引用的行中出现了这个AccessViolationException,因此我假设这是导致targetingException异常的异常 另外,如果我在上面的一行(result=JSEvaluateSc

此错误将随机发生。我知道
\u context
jsScript
不为空。奇怪的是,当错误发生时,Program.cs文件打开,异常出现在
Application.Run(new Form1())上行带有一个
targetingException
,但我可以在IntelliTrace中看到,就在这之前,在上面引用的行中出现了这个
AccessViolationException
,因此我假设这是导致
targetingException
异常的异常

另外,如果我在上面的一行(
result=JSEvaluateScript…
)中设置一个断点,然后在后面设置另一个断点,第一个断点将被命中,然后我按F10,第二个断点将不会被命中,因此异常应该发生在第一个断点上。另外,
JSEvaluateScript
位于
WebKit
dll中,因此我无法进入它

但是,
try/catch
,它本来不在那里,但似乎没有捕捉到异常,所以我不确定发生了什么。我可以通过在应用程序中执行一组操作来重现错误,但无法理解为什么这些操作会导致错误。大多数情况下,使用相同参数调用
JSContext::EvaluateScript
不会导致异常

有没有关于如何诊断的建议?我没有主意了

编辑:我刚刚做了一些调试,错误也可能发生在其他一些随机行上。所以我很确定这与上面的一行无关

编辑2:以下是堆栈跟踪:

>   JSCore.dll!WebKit.JSCore.JSContext.EvaluateScript(string script = {unknown}, object thisObject = {unknown}, string sourceUrl = {unknown}, int startingLineNumber = {unknown})   
    JSCore.dll!WebKit.JSCore.JSContext.EvaluateScript(string script = {unknown})    
    WebKitBrowserTest.exe!Player.WebKitWraps.JSObjectWrap.GetExpando()  
    WebKitBrowserTest.exe!Get Player.WebKitWraps.JSObjectWrap.Expando() 
    WebKitBrowserTest.exe!Player.WebKitWraps.JSObjectWrap.Equals(Player.WebKitWraps.JSObjectWrap other = {Player.WebKitWraps.ElementWrap})  
    WebKitBrowserTest.exe!Player.WebKitWraps.JSObjectWrap.op_Equality(Player.WebKitWraps.JSObjectWrap a = {Player.WebKitWraps.ElementWrap}, Player.WebKitWraps.JSObjectWrap b = {Player.WebKitWraps.ElementWrap})   
    WebKitBrowserTest.exe!Player.WebKitWraps.JSObjectWrap.op_Inequality(Player.WebKitWraps.JSObjectWrap a = {Player.WebKitWraps.ElementWrap}, Player.WebKitWraps.JSObjectWrap b = {Player.WebKitWraps.ElementWrap}) 
    WebKitBrowserTest.exe!WebScraperAndPlayer.SelectionEditor.SelectPrevSibling(WebScraperAndPlayer.BrowserSelector selector = {WebScraperAndPlayer.BrowserSelector})   
    WebKitBrowserTest.exe!WebScraperAndPlayer.SelectionEditor.WillSelectAny(System.Action<WebScraperAndPlayer.BrowserSelector> selectFunction = {System.Action<WebScraperAndPlayer.BrowserSelector>})   
    WebKitBrowserTest.exe!WebScraperAndPlayer.SelectionEditor.UpdateAbilities() 
    WebKitBrowserTest.exe!WebScraperAndPlayer.SelectionEditor.SetExecutionState(Player.Actions.ExecutionState value = Stopped)  
    WebKitBrowserTest.exe!Set WebScraperAndPlayer.SelectionEditor.ExecutionState(Player.Actions.ExecutionState value = Stopped) 
    mscorlib.dll!System.RuntimeMethodHandle.InvokeMethodFast(System.IRuntimeMethodInfo method = {unknown}, object target = {unknown}, object[] arguments = {unknown}, System.Signature sig = {unknown}, System.Reflection.MethodAttributes methodAttributes = {unknown}, System.RuntimeType typeOwner = {unknown})  
    mscorlib.dll!System.Reflection.RuntimeMethodInfo.Invoke(object obj = {unknown}, System.Reflection.BindingFlags invokeAttr = {unknown}, System.Reflection.Binder binder = {unknown}, object[] parameters = {unknown}, System.Globalization.CultureInfo culture = {unknown}, bool skipVisibilityChecks = {unknown})   
    mscorlib.dll!System.Reflection.RuntimeMethodInfo.Invoke(object obj = {unknown}, System.Reflection.BindingFlags invokeAttr = {unknown}, System.Reflection.Binder binder = {unknown}, object[] parameters = {unknown}, System.Globalization.CultureInfo culture = {unknown})  
    mscorlib.dll!System.Reflection.MethodBase.Invoke(object obj = {unknown}, object[] parameters = {unknown})   
    System.dll!System.SecurityUtils.MethodInfoInvoke(System.Reflection.MethodInfo method = {unknown}, object target = {unknown}, object[] args = {unknown}) 
    System.dll!System.ComponentModel.ReflectPropertyDescriptor.SetValue(object component = {unknown}, object value = {unknown}) 
    System.Windows.Forms.dll!System.Windows.Forms.Binding.SetPropValue(object value = {unknown})    
    System.Windows.Forms.dll!System.Windows.Forms.Binding.PushData(bool force = {unknown})  
    System.Windows.Forms.dll!System.Windows.Forms.Binding.PushData()    
    System.Windows.Forms.dll!System.Windows.Forms.BindingManagerBase.PushData(out bool success = {unknown}) 
    System.Windows.Forms.dll!System.Windows.Forms.BindingManagerBase.PushData() 
    System.Windows.Forms.dll!System.Windows.Forms.PropertyManager.OnCurrentChanged(System.EventArgs ea = {unknown}) 
    System.Windows.Forms.dll!System.Windows.Forms.BindToObject.PropValueChanged(object sender = {unknown}, System.EventArgs e = {unknown})  
    System.dll!System.ComponentModel.PropertyDescriptor.OnValueChanged(object component = {unknown}, System.EventArgs e = {unknown})    
    System.dll!System.ComponentModel.ReflectPropertyDescriptor.OnValueChanged(object component = {unknown}, System.EventArgs e = {unknown}) 
    System.dll!System.ComponentModel.ReflectPropertyDescriptor.OnINotifyPropertyChanged(object component = {unknown}, System.ComponentModel.PropertyChangedEventArgs e = {unknown}) 
    WebKitBrowserTest.exe!Player.Project.BasicProject.NotifyPropertyChanged(string propertyName = "ExecutionState") 
    WebKitBrowserTest.exe!Player.Project.BasicProject.SetInternalExecutionState(InternalExecutionState value = Stopped) 
    WebKitBrowserTest.exe!Player.Project.BasicProject.execData_ExecutionCompleted(object sender = {Player.Actions.ExecutionData}, Player.Actions.ExecutionCompletedEventArgs e = {Player.Actions.ExecutionCompletedEventArgs})  
    WebKitBrowserTest.exe!Player.Actions.ExecutionData.OnExecutionCompleted(Player.Actions.ExecutionCompletedEventArgs e = {Player.Actions.ExecutionCompletedEventArgs})    
    WebKitBrowserTest.exe!Player.Actions.ExecutionData.ReportExecutionCompleted(Player.Actions.StopException exception = null)  
    WebKitBrowserTest.exe!Player.Actions.Executor.ProcessExecutionCompleted(Player.Actions.StopException exception = null)  
    WebKitBrowserTest.exe!Player.Actions.Executor.StartNextSegment()    
    WebKitBrowserTest.exe!Segment.Conclude()    
    WebKitBrowserTest.exe!<>c__DisplayClass5.AnonymousMethod()  
    WebKitBrowserTest.exe!Player.Actions.Waiter.OnCallbackFunction()    
    WebKitBrowserTest.exe!Player.Actions.Waiter.Complete()  
    WebKitBrowserTest.exe!Player.Actions.Waiter.AnonymousMethod()   
    mscorlib.dll!System.RuntimeMethodHandle.InvokeMethodFast(System.IRuntimeMethodInfo method = {unknown}, object target = {unknown}, object[] arguments = {unknown}, System.Signature sig = {unknown}, System.Reflection.MethodAttributes methodAttributes = {unknown}, System.RuntimeType typeOwner = {unknown})  
    mscorlib.dll!System.Reflection.RuntimeMethodInfo.Invoke(object obj = {unknown}, System.Reflection.BindingFlags invokeAttr = {unknown}, System.Reflection.Binder binder = {unknown}, object[] parameters = {unknown}, System.Globalization.CultureInfo culture = {unknown}, bool skipVisibilityChecks = {unknown})   
    mscorlib.dll!System.Delegate.DynamicInvokeImpl(object[] args = {unknown})   
    mscorlib.dll!System.Delegate.DynamicInvoke(object[] args = {unknown})   
    System.Windows.Forms.dll!System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme = {unknown})  
    System.Windows.Forms.dll!System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(object obj = {unknown}) 
    mscorlib.dll!System.Threading.ExecutionContext.runTryCode(object userData = {unknown})  
    mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext = {unknown}, System.Threading.ContextCallback callback = {unknown}, object state = {unknown}) 
    mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext = {unknown}, System.Threading.ContextCallback callback = {unknown}, object state = {unknown}, bool ignoreSyncCtx = {unknown}) 
    mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext = {unknown}, System.Threading.ContextCallback callback = {unknown}, object state = {unknown}) 
    System.Windows.Forms.dll!System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme = {unknown})    
    System.Windows.Forms.dll!System.Windows.Forms.Control.InvokeMarshaledCallbacks()    
    System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m = {unknown})   
    System.Windows.Forms.dll!System.Windows.Forms.ScrollableControl.WndProc(ref System.Windows.Forms.Message m = {unknown}) 
    System.Windows.Forms.dll!System.Windows.Forms.ContainerControl.WndProc(ref System.Windows.Forms.Message m = {unknown})  
    System.Windows.Forms.dll!System.Windows.Forms.Form.WndProc(ref System.Windows.Forms.Message m = {unknown})  
    System.Windows.Forms.dll!ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m = {unknown})  
    System.Windows.Forms.dll!ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m = {unknown})    
    System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd = {unknown}, int msg = {unknown}, System.IntPtr wparam = {unknown}, System.IntPtr lparam = {unknown})  
    System.Windows.Forms.dll!ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(System.IntPtr dwComponentID = {unknown}, int reason = {unknown}, int pvLoopData = {unknown})   
    System.Windows.Forms.dll!ThreadContext.RunMessageLoopInner(int reason = {unknown}, System.Windows.Forms.ApplicationContext context = {unknown}) 
    System.Windows.Forms.dll!ThreadContext.RunMessageLoop(int reason = {unknown}, System.Windows.Forms.ApplicationContext context = {unknown})  
    System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.Form mainForm = {unknown})   
    WebKitBrowserTest.exe!WebScraperAndPlayer.Program.Main(string[] args = {string[0]}) 
>JSCore.dll!WebKit.JSCore.JSContext.EvaluateScript(字符串脚本={unknown},对象thisObject={unknown},字符串sourceUrl={unknown},int startingLineNumber={unknown})
JSCore.dll!WebKit.JSCore.JSContext.EvaluateScript(字符串脚本={unknown})
WebKitBrowserTest.exe!Player.webkitwrap.JSObjectWrap.GetExpando()
WebKitBrowserTest.exe!获取Player.webkitwrap.JSObjectWrap.Expando()
WebKitBrowserTest.exe!Player.webkitwrap.JSObjectWrap.Equals(Player.webkitwrap.JSObjectWrap-other={Player.webkitwrap.ElementWrap})
WebKitBrowserTest.exe!Player.webkitwrap.JSObjectWrap.op_相等(Player.webkitwrap.JSObjectWrap a={Player.webkitwrap.ElementWrap},Player.webkitwrap.JSObjectWrap b={Player.webkitwrap.ElementWrap})
WebKitBrowserTest.exe!Player.webkitwrap.JSObjectWrap.op_不等式(Player.webkitwrap.JSObjectWrap a={Player.webkitwrap.ElementWrap},Player.webkitwrap.JSObjectWrap b={Player.webkitwrap.ElementWrap})
WebKitBrowserTest.exe!WebScraperAndLayer.SelectionEditor.SelectPrevSibling(WebScraperAndLayer.BrowserSelector={WebScraperAndLayer.BrowserSelector})
WebKitBrowserTest.exe!WebScraperAndLayer.SelectionEditor.WillSelectAny(System.Action selectFunction={System.Action})
WebKitBrowserTest.exe!WebScraperAndLayer.SelectionEditor.UpdateAbilities()
WebKitBrowserTest.exe!WebScraperAndPlayer.SelectionEditor.SetExecutionState(Player.Actions.ExecutionState值=已停止)
WebKitBrowserTest.exe!设置WebScraperAndLayer.SelectionEditor.ExecutionState(Player.Actions.ExecutionState值=已停止)
mscorlib.dll!System.RuntimeMethodHandle.InvokeMethodFast(System.IRuntimeMethodInfo方法={unknown},对象目标={unknown},对象[]参数={unknown},System.Signature sig={unknown},System.Reflection.MethodAttributes方法属性={unknown},System.RuntimeType typeOwner={unknown})
mscorlib.dll!System.Reflection.RuntimeMethodInfo.Invoke(对象obj={unknown},System.Reflection.BindingFlags invokeAttr={unknown},System.Reflection.Binder Binder={unknown},对象[]参数={unknown},System.Globalization.CultureInfo文化={unknown},布尔skipVisibilityChecks={unknown})
mscorlib.dll!System.Reflection.RuntimeMethodInfo.Invoke(对象obj={unknown},System.Reflection.BindingFlags invokeAttr={unknown},System.Reflection.Binder Binder={unknown},对象[]参数={unknown},System.Globalization.CultureInfo文化={unknown})
mscorlib.dll!System.Reflection.MethodBase.Invoke(对象obj={unknown},对象[]参数={unknown})
System.dll!System.SecurityUtils.MethodInfoInvoke(System.Reflection.MethodInfo方法={unknown},对象目标={unknown},对象[]args={unknown})
System.dll!System.ComponentModel.ReflectPropertyDescriptor.SetValue(对象组件={unknown},对象值={unknown})
System.Windows.Forms.dll!System.Windows.Forms.Binding.SetPropValue(对象值={unknown})
System.Windows.Forms.dll!System.Windows.Forms.Binding.PushData(bool force={unknown})
System.Windows.Forms.dll!System.Windows.Forms.Binding.PushData()
System.Windows.Forms.dll!System.Windows.Forms.BindingManagerBase.PushData(out bool success={unknown})
System.Windows.Forms.dll!System.Windows.Forms.BindingManagerBase.PushData()
System.Windows.Forms.dll!System.Windows.Forms.PropertyManager.OnCurrentChanged(System.EventArgs ea={unknown})
System.Windows.Forms.dll!System.Windows.Forms.BindToObject.PropValueChanged(对象发送方={unknown},System.EventArgs e={unknown})
System.dll!System.ComponentModel.PropertyDescriptor.OnValueChanged(对象组件={unknown},System.EventArgs e={unknown})
System.dll!System.ComponentModel.ReflectPropertyDescriptor.OnValueChanged(对象组件={unknown},System.EventArgs e={unknown})
System.dll!System.ComponentModel.ReflectPropertyDescriptor.OnNotifyProperty