相关疑难解决方法(0)

如何处理AccessViolationException

我在我的.net应用程序中使用COM对象(MODI).我调用的方法抛出一个System.AccessViolationException,它被Visual Studio拦截.奇怪的是我在try catch中包含了我的调用,它包含AccessViolationException,COMException和其他所有东西的处理程序,但是当Visual Studio(2010)拦截AccessViolationException时,调试器会中断方法调用(doc.OCR),如果我单步执行,它将继续到下一行,而不是进入catch块.另外,如果我在visual studio外部运行,我的应用程序崩溃了.如何处理COM对象中引发的此异常?

MODI.Document doc = new MODI.Document();
try
{
    doc.Create(sFileName);
    try
    {
        doc.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, false, false);
        sText = doc.Images[0].Layout.Text;
    }
    catch (System.AccessViolationException ex)
    {
        //MODI seems to get access violations for some reason, but is still able to return the OCR text.
        sText = doc.Images[0].Layout.Text;
    }
    catch (System.Runtime.InteropServices.COMException ex)
    {
        //if no text exists, the engine throws an exception.
        sText = "";
    }
    catch
    {
        sText = "";
    }

    if (sText != null)
    {
        sText = sText.Trim();
    } …
Run Code Online (Sandbox Code Playgroud)

.net c# com modi exception

170
推荐指数
3
解决办法
13万
查看次数

尝试读取或写入受保护的内存

我已经开始看到一个AccessViolationException被我的应用程序抛出了几个不同的位置.它从未出现在我的开发PC上,我们的测试服务器上.它也仅在我们的2个生产服务器中的一个上显示出来.因为它似乎只发生在我们的一个生产服务器上,所以我开始在服务器上查看已安装的.net框架版本.


我发现(出于一些奇怪的原因),出现问题的生产服务器有2.0 sp2,3.0 sp2和3.5 sp1,而另一个生产服务器和测试服务器有2.0 sp1.


我的应用程序仅针对2.0框架,决定从生产服务器卸载所有框架版本并仅安装2.0 sp1.到目前为止,我还没有能够重现这个问题.很有意思.

开发pc:紧凑型2.0 sp2,紧凑型3.5,2.0 sp2,3.0 sp2,3.5 sp1测试服务器:2.0 sp1生产服务器1:2.0 sp1生产服务器2:2.0 sp2,3.0 sp2,3.5 sp1

现在,为什么我无法重现问题我的开发pc上有2.0 sp2,我想不出来.我听说有传言说这种访问违规可能发生在一些使用远程处理的软件上,我的确如此,但是当实际进行远程处理时,访问冲突永远不会发生.我现在只使用2.0 sp1,但我真的很想知道是否有人遇到过这个问题,如果他们找到了更新版本的frameowork的解决方法.

这里有几个例外和它们的堆栈跟踪:

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at ICSharpCode.TextEditor.TextArea.HandleKeyPress(Char ch)
   at ICSharpCode.TextEditor.TextArea.SimulateKeyPress(Char ch)
   at ICSharpCode.TextEditor.TextArea.OnKeyPress(KeyPressEventArgs e)
   at System.Windows.Forms.Control.ProcessKeyEventArgs(Message& m)
   at System.Windows.Forms.Control.ProcessKeyMessage(Message& m)
   at System.Windows.Forms.Control.WmKeyChar(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

System.AccessViolationException: Attempted to read …
Run Code Online (Sandbox Code Playgroud)

.net c# servicepacks access-violation

37
推荐指数
3
解决办法
13万
查看次数

标签 统计

.net ×2

c# ×2

access-violation ×1

com ×1

exception ×1

modi ×1

servicepacks ×1