亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何處理AccessViolationException

如何處理AccessViolationException

呼啦一陣風 2019-07-05 12:56:34
如何處理AccessViolationException我在.NET應用程序中使用COM對象(Modi)。我所調用的方法拋出一個System.AccessViolationException,該異常被VisualStudio截獲。奇怪的是,我已經將調用包裝在一個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();     }}finally{     doc.Close(false);     //Cleanup routine, this is how we are able to delete files used by MODI.     System.Runtime.InteropServices.Marshal.FinalReleaseComObject(doc);     doc = null;     GC.WaitForPendingFinalizers();     GC.Collect();     GC.WaitForPendingFinalizers();}
查看完整描述

3 回答

?
米脂

TA貢獻1836條經驗 獲得超3個贊

在配置文件中添加以下內容,它將被捕獲在TRINCATCH塊中。警告的話.。盡量避免這種情況,因為這意味著某種違法行為正在發生。

<configuration>
   <runtime>
      <legacyCorruptedStateExceptionsPolicy enabled="true" />
   </runtime></configuration>


查看完整回答
反對 回復 2019-07-05
  • 3 回答
  • 0 關注
  • 1045 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號