ArcEngine10.2及以下版本轉換成ArcEngine10.4及以上版本 異常來自HRESULT:0x80040228

 

AE開發中打開shp經常會用到以下的代碼:

IWorkspaceFactory testfactory = new ShapefileWorkspaceFactory();
IWorkspace testwork = testfactory.OpenFromFile(foldername, 0);

之前用的版本vs2015+AE10.2.2一直好好的,換成AE10.4版本之後報錯:異常來自HRESULT:0x80040228。

這個錯誤基本上是axcontrol控件、AE許可方面的問題。看了網上的解決辦法,大多數是以下兩種方法:

1、界面上添加axcontrol控件(我的已有)

2、program頁面裏添加:

using ESRI.ArcGIS.esriSystem
IAoInitialize m_aoinitialize = new AoInitializeClass();
m_aoinitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcInfo);

試了之後也是無效的。最終參考了以下兩篇文章,驗證是有效的。

https://blog.csdn.net/qq_29176825/article/details/84864939

https://www.cnblogs.com/liweis/p/8675903.html

做了修改後的終極方法:在program頁面裏添加:

ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop);
//以下爲新增的代碼
IAoInitialize aoInit = new AoInitializeClass();        
aoInit.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcServer);

待修改程序的Program.cs文件爲如下所示: (其中XXXX與xxxxx分別填程序的命名空間與要啓動的窗體名稱)

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using ESRI.ArcGIS;
using ESRI.ArcGIS.esriSystem;
 
namespace XXXX    //XXXX爲程序的命名空間
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            if (!RuntimeManager.Bind(ProductCode.Engine))
            {
                if (!RuntimeManager.Bind(ProductCode.Desktop))
                {
                    MessageBox.Show("Unable to bind to ArcGIS runtime. Application will be shut down.");
                    return;
                }
            }
            IAoInitialize m_aoinitialize = new AoInitializeClass();
            m_aoinitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new xxxxx);  //xxxxx爲你要啓動的窗體名稱
        }
    }
}

3、第三種情況:由於AE未破解的緣故,只破解desktop並不行。需將破解文件中的afcore.dll(與desktop等同),將此文件拷貝到engine10.4文件夾下的bin子文件夾,替換原許可文件。這時就可以成功。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章