Accessing licensing and extensions for the geoprocessor (ArcObjects .NET 10.6 SDK)
ArcObjects Help for .NET developers > Developing with ArcGIS > Learning ArcObjects > Using geoprocessing > Executing tools > Accessing licensing and extensions for the geoprocessor (ArcObjects .NET 10.6 SDK)

Accessing licensing and extensions for the geoprocessor


About accessing licensing and extensions for the geoprocessor

An ArcGIS Desktop license is required to execute a tool in a program. Tools from ArcGIS extensions, such as ArcGIS Spatial Analyst, require an additional license for that extension. If the necessary licenses are not available, a tool fails and returns the appropriate error messages.
Starting at ArcGIS 10, you need to set the product that will execute the code by the RuntimeManager. Add ESRI.ArcGIS.Version to your project as a reference. However, you don't need to add the namespace to your code with the using keyword.
When using an ArcGIS Desktop Basic or Standard license, a program must explicitly use AoIntialize, and the product must be set to Basic or Standard or the program fails. By default, the geoprocessor always assumes an ArcGIS Desktop Advanced license is required for execution of a tool. See the following code example:
[C#]
static void Main(string[] args)
{
    // Add runtime management.  
    ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop);

    //Initialize the application.
    esriLicenseStatus licenseStatus=esriLicenseStatus.esriLicenseUnavailable;
    IAoInitialize m_AoInitialize=new AoInitializeClass();
    licenseStatus=m_AoInitialize.Initialize
        (esriLicenseProductCode.esriLicenseProductCodeAdvanced);
    licenseStatus=m_AoInitialize.CheckOutExtension
        (esriLicenseExtensionCode.esriLicenseExtensionCodeSpatialAnalyst);

    // Initialize the geoprocessor.         
    Geoprocessor gp=new Geoprocessor();
    Slope tSlope=new Slope();
    tSlope.in_raster=@"E:\Data\demlatgrd";
    tSlope.out_raster=@"E:\Data\aspect03";
    gp.Execute(tSlope, null);

    licenseStatus=m_AoInitialize.CheckInExtension
        (esriLicenseExtensionCode.esriLicenseExtensionCodeSpatialAnalyst);
    m_AoInitialize.Shutdown();
    m_AoInitialize=null;

}
[VB.NET]
Shared Sub Main(ByVal args As String())

'Add runtime management.
ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop)

'Initialize the application.
Dim licenseStatus As esriLicenseStatus=esriLicenseStatus.esriLicenseUnavailable
Dim m_AoInitialize As IAoInitialize=New AoInitializeClass()
licenseStatus=m_AoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeAdvanced)
licenseStatus=m_AoInitialize.CheckOutExtension(esriLicenseExtensionCode.esriLicenseExtensionCodeSpatialAnalyst)

' Initialize the geoprocessor.
Dim gp As Geoprocessor=New Geoprocessor()
Dim tSlope As ESRI.ArcGIS.SpatialAnalystTools.Slope=New ESRI.ArcGIS.SpatialAnalystTools.Slope()
tSlope.in_raster="E:\Data\demlatgrd"
tSlope.out_raster="E:\Data\aspect03"
gp.Execute(tSlope, Nothing)

licenseStatus=m_AoInitialize.CheckInExtension(esriLicenseExtensionCode.esriLicenseExtensionCodeSpatialAnalyst)
m_AoInitialize.Shutdown()
m_AoInitialize=Nothing

End Sub


See Also:

AoInitializeClass




To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):