Error: Error: The instruction at "0xxxxxxx" referenced could not be read

文章编号 : 26958
软件: ArcGIS - ArcEditor 9.0, 9.1 ArcGIS - ArcInfo 9.0, 9.1 ArcGIS - ArcView 9.0, 9.1 ArcGIS Engine Developer Kit 9.0
操作系统: Windows 2000, XP
已邀请:

EsriSupport

赞同来自:

错误信息:
使用Visual Studio .net写的Engine和Desktop应用程序,在退出程序时可能会出现崩溃的现象,出现如
下的错误信息: "The instruction at "0xxxxxx" referenced could not be read."
原因: com对象间出现不可预期的冲突导致的

解决方法:
所有的com对象在程序关闭前必须被销毁,因此可以用一个静态方法来执行,可以采用以下方法来实现
[Visual Basic .NET] Private Sub Form1_Closing(ByVal sender As Object, ByVal e As

System.ComponentModel.CancelEventArgs) Handles MyBase.Closing ESRI.ArcGIS.Utility.COMSupport.AOUninitialize.Shutdown() End Sub
[C#] private void Form1_Closing(object sender, CancelEventArgs e) { ESRI.ArcGIS.Utility.COMSupport.AOUninitialize.Shutdown(); }
关闭程序时,除了AOUninitalize.Shutdown这个方法最容易出问题外,还有其它com对象没释放好也易出
问题,这时我们可以调用System.Runtime.InteropServices.Marshal.ReleaseComObject()来将com对象
释放干净。例如styleGallery对象,下面就以这个对象为例子来说明如何释放com对象。
[Visual Basic .NET] Dim styleGallery As IStyleGallery
styleGallery = New StyleGalleryClass
MessageBox.Show(styleGallery.ClassCount)
Marshal.ReleaseComObject(styleGallery)

[C#] IStyleGallery sg = new StyleGalleryClass() as IStyleGallery;
MessageBox.Show(sg.ClassCount.ToString());
Marshal.ReleaseComObject(sg);



创建时间:2004-06-08
最近更新: 2008-04-28


原文链接
http://support.esrichina.com.c ... .html

要回复问题请先登录注册