ProConcepts CoreHost - kataya/arcgis-pro-sdk GitHub Wiki
This topic provides a brief introduction to building stand-alone apps with the ArcGIS Pro ArcGIS.CoreHost and ArcGIS.Core assemblies.
ArcGIS.CoreHost.dll
ArcGIS.Core.dll
Language: C#
Subject: CoreHost
Contributor: ArcGIS Pro SDK Team <[email protected]>
Organization: Esri, http://www.esri.com
Date: 11/24/2020
ArcGIS Pro: 2.7
Visual Studio: 2017, 2019
ArcGIS.Core.dll provides 64-bit access to the Geodatabase and Geometry classes used by ArcGIS Pro. This assembly can be referenced in either an ArcGIS Pro Add-in or embedded in a console or WPF app. Unlike in an add-in, when ArcGIS.Core.dll is used in a console app (or WPF app), you must first initialize the underlying environment by calling the static Host.Initialize
method on the ArcGIS.Core.Hosting.Host
class located in the ArcGIS.CoreHost assembly. After initialization, any of the ArcGIS.Core.dll types can be constructed and accessed. (Note: Attempting to access any of the ArcGIS Pro UI elements or types in other assemblies in an ArcEngine-like fashion will crash your program).
This topic walks you through the procedure for configuring your app to run ArcGIS.Core external to the ArcGIS Pro Add-in framework.
- ArcGIS Pro must be installed on either the developer machine or the host machine on which your program will be run.
- You must configure your ArcGIS Pro license settings in one of the following ways:
- Single Use License
- Concurrent Use License
- Named User License --and--
- Either:
- Check the Authorize ArcGIS Pro to work offline check box on the Backstage tab --or--
- Check the Sign me in automatically check box on the ArcGIS Sign In pop-up.
Backstage Authorize ArcGIS Pro to work offline
ArcGIS Sign In Sign me in automatically (for Named User License)
In Visual Studio, create a new console application. Add references to the following two DLLs, both located in the ArcGIS Pro bin folder:
- ArcGIS.CoreHost.dll
- ArcGIS.Core.dll
Note: Ensure your target framework is set to 4.8*.
*4.6.1 or later for Pro v2.0 - 2.4.
On the Build properties dialog box of your project, change the Platform Target combo box to be x64 (by default it will be Any CPU).
In your code, add the [STAThread]
attribute above the console's static Main(string[] args)
method. The presence of the STAThread
attribute forces the application's primary thread to initialize as an STA thread the first time the application does any interoperability work with COM (for example, via the first call to a type in ArcGIS.Core.dll).
Initialize the Host
class before accessing any types within the ArcGIS.Core assembly. To initialize the Host
class, call its static Initialize
method:
class Program {
//[STAThread] must be present on the Application entry point
[STAThread]
static void Main(string[] args) {
//Call Host.Initialize before constructing any objects from ArcGIS.Core
try {
Host.Initialize();
}
catch (Exception e) {
// Error (missing installation, no license, 64 bit mismatch, etc.)
Console.WriteLine(string.Format("Initialization failed: {0}",e.Message));
return;
}
There is no return value. If initialization is successful, program execution will continue, and ArcGIS.Core functionality can be accessed. If initialization fails, a System.Exception
will be thrown on the Initialize call.
Note: You do not need to call a shutdown method to unload the ArcGIS.Core assembly (similar to IAoInitialize.Shutdown
in ArcObjects).
Host.Initialize
checks:
- Is the Program 64 bit?
- Is the process COM threading model single-threaded apartment (STA)?
- Is ArcGIS Pro installed?
- Can ArcGIS Pro licensing be initialized? (See prerequisites)
Any failure in the initialization sequence will result in a System.Exception
. Check the returned message in the System.Exception
from Host.Initialize, and take the appropriate corrective action.
Automating ArcGIS Pro Mapping is supported in arcpy.mp. You can find more information in What is ArcPy?.
In order to edit datasets in a Geodatabase while running ArcGIS.Core external to the ArcGIS Pro Add-in framework, the ArcGIS.Core.Data namespace provides the Geodatabase.ApplyEdits method. See Editing in stand-alone mode for more details.
The prerequisites for deploying an executable taking advantage of ArcGIS.CoreHost.dll and ArcGIS.Core.dll are as follows:
- ArcGIS Pro must be installed on the host machine.
- The licensing prerequisites must be met when the program is run.