今天在写插件程序的时候遇到这样一个问题:在VS2005的一个WinForm上拖放一个AxMapControl控件,运行,没有任何错误;但是双击AxMapControl控件后再运行,就会出错,错误信息为:
类型“ESRI.ArcGIS.MapControl.IMapControlEvents2_OnMouseDownEventHandler”同时存在于“f:/Program Files/ArcGIS/DotNet/ESRI.ArcGIS.AxMapControl.dll”和“f:/Program Files/ArcGIS/DotNet/ESRI.ArcGIS.MapControl.dll”中 E:/C#2005 Programming/WindowsApplication1/WindowsApplication1/Form1.Designer.cs 43 74 WindowsApplication1
另外,在自定义事件的时候也常常出现这种错误,意思大概是AxMapControl和MapControl之间存在一定冲突。以前用VS2003+AE9.1或者VS2005+AE9.2都没有出现这种问题,我想这应该是ESRI的一个bug吧。后来在baidu上找到了解决方法:
第一步:在解决方案资源管理器中,选中“ESRI.ArcGIS.AxMapControl”项,在属性栏中,将其别名由“global”改为“global, MapControlAlias”;
第二步:在using出添加饮用为,extern alias MapControlAlias;
第三步:在事件加“MapControlAlias::”。
改动结果为:
extern alias MapControlAlias;
using System;
using System.Collections.Generic;
using System.Text;
using PluginFramework;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.MapControl;
……
this.application.axMapControl.OnMouseDown+=new MapControlAlias::ESRI.ArcGIS.MapControl.IMapControlEvents2_OnMouseDownEventHandler(this.axMapControl_OnMouseDown);
改动之后再运行,不报错。因为水平差,原因不明。