解决System.Runtime.InteropServices.COMException:“指定的路径无效”问题

586 阅读1分钟

Bug背景

简单说一下开发环境,IDE:VS2022,二次开发框架: ArcObject 10.2,由于无法将控件以直接拖放的形式添加到窗口中,为此,需要手写代码添加地图控件,如下:

AxMapControl _mapControl = new AxMapControl();
tabControl2.TabPages[0].Controls.Add(_mapControl);
_mapControl.Dock = DockStyle.Fill;

但是在添加数据(如:shp数据)时,会出现bug:System.Runtime.InteropServices.COMException:“指定的路径无效”

网上查了资料说要加入AxLicenseControl,但是bug依然存在

解决方法

在界面初始化部分可以添加如下代码,初始化许可:

IAoInitialize aoInit = new AoInitialize();
esriLicenseStatus licenseStatus = aoInit.Initialize(esriLicenseProductCode.esriLicenseProductCodeAdvanced);

现在问题就能解决了