当前位置:编程学习 > 网站相关 >>

求助,在使用arcgis9.3自带的.net DLL例子程序在退出arcmap时报错

我用的是
D:\Program Files\ArcGIS\DeveloperKit\SamplesNET\Desktop\CommandInheritingBaseCommand\CSharp\CommandInheritingBaseCommand
目录下的例子,生成ZoomToLayer.DLL注册到arcmap后在退出arcmap的时候报错:


错误信息如下:

有关调用实时(JIT)调试而不是此对话框的详细信息,
请参见此消息的结尾。

************** 异常文本 **************
System.AccessViolationException: 尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
   在 System.Windows.Forms.UnsafeNativeMethods.IOleInPlaceObject.GetWindow(IntPtr& hwnd)
   在 System.Windows.Forms.AxHost.WndProc(Message& m)
   在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** 已加载的程序集 **************
mscorlib
    程序集版本: 2.0.0.0
    Win32 版本: 2.0.50727.3053 (netfxsp.050727-3000)
    基本代码: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
ContentsView
    程序集版本: 1.0.4727.37063
    Win32 版本: 1.0.4727.37063
    基本代码: file:///C:/ContentsView.DLL
----------------------------------------
ESRI.ArcGIS.ArcMapUI
    程序集版本: 9.3.0.1770
    Win32 版本: 9.3.0.1770
    基本代码: file:///C:/WINDOWS/assembly/GAC_MSIL/ESRI.ArcGIS.ArcMapUI/9.3.0.1770__8fc3cc631e44ad86/ESRI.ArcGIS.ArcMapUI.dll
----------------------------------------
System.Windows.Forms
    程序集版本: 2.0.0.0
    Win32 版本: 2.0.50727.3053 (netfxsp.050727-3000)
    基本代码: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
    程序集版本: 2.0.0.0
    Win32 版本: 2.0.50727.3053 (netfxsp.050727-3000)
    基本代码: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
    程序集版本: 2.0.0.0
    Win32 版本: 2.0.50727.3053 (netfxsp.050727-3000)
    基本代码: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
ESRI.ArcGIS.AxControls
    程序集版本: 9.3.0.1770
    Win32 版本: 9.3.0.1770
    基本代码: file:///C:/WINDOWS/assembly/GAC_MSIL/ESRI.ArcGIS.AxControls/9.3.0.1770__8fc3cc631e44ad86/ESRI.ArcGIS.AxControls.dll
----------------------------------------
ESRI.ArcGIS.Controls
    程序集版本: 9.3.0.1770
    Win32 版本: 9.3.0.1770
    基本代码: file:///C:/WINDOWS/assembly/GAC_MSIL/ESRI.ArcGIS.Controls/9.3.0.1770__8fc3cc631e44ad86/ESRI.ArcGIS.Controls.dll
----------------------------------------
Accessibility
    程序集版本: 2.0.0.0
    Win32 版本: 2.0.50727.3053 (netfxsp.050727-3000)
    基本代码: file:///C:/WINDOWS/assembly/GAC_MSIL/Accessibility/2.0.0.0__b03f5f7f11d50a3a/Accessibility.dll
----------------------------------------
System.Windows.Forms.resources
    程序集版本: 2.0.0.0
    Win32 版本: 2.0.50727.3053 (netfxsp.050727-3000)
    基本代码: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms.resources/2.0.0.0_zh-CHS_b77a5c561934e089/System.Windows.Forms.resources.dll
----------------------------------------
mscorlib.resources
    程序集版本: 2.0.0.0
    Win32 版本: 2.0.50727.3053 (netfxsp.050727-3000)
    基本代码: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------

************** JIT 调试 **************
要启用实时(JIT)调试,
该应用程序或计算机的 .config 文件(machine.config)的 system.windows.forms 节中必须设置
jitDebugging 值。
编译应用程序时还必须启用
调试。

例如: 

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

启用 JIT 调试后,任何无法处理的异常
都将被发送到在此计算机上注册的 JIT 调试器,
而不是由此对话框处理。

那个示例的源程序如下

using System;
using System.Drawing;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.ADF.CATIDs;
using ESRI.ArcGIS.Framework;
using ESRI.ArcGIS.ArcMapUI;

namespace CommandInheritingBaseCommand
{
    
    [Guid("46bd0933-acac-4c33-8669-1255db03ca5c")]
    [ClassInterface(ClassInterfaceType.None)]
    [ProgId("CommandInheritingBaseCommand.ZoomToLayer")]
    public sealed class ZoomToLayer : BaseCommand
    {
        #region COM Registration Function(s)
        [ComRegisterFunction()]
        [ComVisible(false)]
        static void RegisterFunction(Type registerType)
        {
            // Required for ArcGIS Component Category Registrar support
            ArcGISCategoryRegistration(registerType);

            //
            // TODO: Add any COM registration code here
            //
        }

        [ComUnregisterFunction()]
        [ComVisible(false)]
        static void UnregisterFunction(Type registerType)
        {
            // Required for ArcGIS Component Category Registrar support
            ArcGISCategoryUnregistration(registerType);

            //
            // TODO: Add any COM unregistration code here
            //
        }

        #region ArcGIS Component Category Registrar generated code
        /// <summary>
        /// Required method for ArcGIS Component Category registration -
        /// Do not modify the contents of this method with the code editor.
        /// </summary>
        private static void ArcGISCategoryRegistration(Type registerType)
        {
            string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
            MxCommands.Register(regKey);

        }
        /// <summary>
        /// Required method for ArcGIS Component Category unregistration -
        /// Do not modify the contents of this method with the code editor.
        /// </summary>
        private static void ArcGISCategoryUnregistration(Type registerType)
        {
            string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
            MxCommands.Unregister(regKey);

        }

        #endregion
        #endregion

        private IApplication m_application;
        public ZoomToLayer()
        {
            //
            // TODO: Define values for the public properties
            //
            base.m_category = "Developer Samples"; //localizable text
            base.m_caption = "Zoom To Layer CSharp"; //localizable text
            base.m_message = "Zoom to the extent of the active layer in the TOC"; //localizable text 
            base.m_toolTip = "Zoom To Layer CSharp"; //localizable text 
            base.m_name = "DeveloperSamples_ZoomToLayerCSharp"; //unique id, non-localizable (e.g. "MyCategory_ArcMapCommand")
            try
            {
                //
                // TODO: change bitmap name if necessary
                //
                string bitmapResourceName = GetType().Name + ".bmp";
                base.m_bitmap = new Bitmap(GetType(), bitmapResourceName);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap");
            }
        }

        #region Overriden Class Methods

        /// <summary>
        /// Occurs when this command is created
        /// </summary>
        /// <param name="hook">Instance of the application</param>
        public override void OnCreate(object hook)
        {
            if (hook == null)
                return;

            m_application = hook as IApplication;

            //Disable if it is not ArcMap
            if (hook is IMxApplication)
                base.m_enabled = true;
            else
                base.m_enabled = false;

            // TODO:  Add other initialization code
        }

        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            IMxDocument mxDocument = GetMxDocument(m_application);
            ZoomToLayerInTOC(mxDocument);
        }

        #endregion

        #region "Zoom to Active Layer in TOC"
        
        public void ZoomToLayerInTOC(ESRI.ArcGIS.ArcMapUI.IMxDocument mxDocument)
        {
            if (mxDocument == null)
            {
                return;
            }
            ESRI.ArcGIS.Carto.IActiveView activeView = mxDocument.ActiveView;

            // Get the TOC
            ESRI.ArcGIS.ArcMapUI.IContentsView IContentsView = mxDocument.CurrentContentsView;

            // Get the selected layer
            System.Object selectedItem = IContentsView.SelectedItem;
            if (!(selectedItem is ESRI.ArcGIS.Carto.ILayer))
            {
                return;
            }
            ESRI.ArcGIS.Carto.ILayer layer = selectedItem as ESRI.ArcGIS.Carto.ILayer;


            // Zoom to the extent of the layer and refresh the map
            activeView.Extent = layer.AreaOfInterest;
            activeView.Refresh();
        }
        #endregion

        #region "Get MxDocument from ArcMap"
        
        public ESRI.ArcGIS.ArcMapUI.IMxDocument GetMxDocument(ESRI.ArcGIS.Framework.IApplication application)
        {

            if (application == null)
            {
                return null;
            }
            ESRI.ArcGIS.ArcMapUI.IMxDocument mxDocument = ((ESRI.ArcGIS.ArcMapUI.IMxDocument)(application.Document)); // Explicit Cast

            return mxDocument;

        }
        #endregion                     
                
    }
}

--------------------编程问答-------------------- 自己顶一下,代码中只有一个new,但是C#不是不用显示删除new的对象吗?
还有就是我在自己开发的电脑上没有问题,注册到别的电脑上才出现的这个问题。 --------------------编程问答-------------------- 自己顶一下!!!!!! --------------------编程问答-------------------- 另外那台机子装AO没有? --------------------编程问答-------------------- 装了再试试~~~ --------------------编程问答--------------------
引用 4 楼 dreamgis 的回复:
装了再试试~~~


装了的啊?

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

启用 JIT 调试后,任何无法处理的异常
都将被发送到在此计算机上注册的 JIT 调试器,
而不是由此对话框处理。

这个怎么在vs2008和 machine.config里面设置?
就是怎么调试这个问题呢? --------------------编程问答--------------------
引用 5 楼 seawaterblue 的回复:
引用 4 楼 dreamgis 的回复:
装了再试试~~~

装了的啊?

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

启用 JIT 调试后,任何无法处理的异常
都将被发送到在此计算机上注册的 JIT 调试器,
而不是由此对话框处理。

这个怎么在vs……


这个不用调试,也不用配置,换一台机子试试,如果另外一台机子不报错,就说明你机子的环境有问题,重装desktop
补充:企业软件 ,  地理信息系统
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,