Handling the LicenseControl initialization failure
- Right-click the LicenseControl, then choose Properties to open the LicenseControl Properties dialog box.
- Select the appropriate check box for the product and extension licenses.
- Clear the Shutdown this application if the selected licenses are not available check box, then click the Apply button. See the following screen shot:
- Add code to import the following namespaces. See the following code:
Imports ESRI.ArcGIS.Controls
Imports ESRI.ArcGIS.esriSystem
[C#]
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.esriSystem;
- Place the following code at the beginning of the application before any other ArcObjects components are run, such as at the beginning in a Sub Main() or a Form_Load():
Dim sFailure As String, sAvailability() As String, i As Integer
'If license initialization failed,
If AxLicenseControl1.Status <> esriLicenseStatus.esriLicenseCheckedOut Then
sFailure = "License initialization failed for the following reason:" + _
Environment.NewLine + AxLicenseControl1.Summary + Environment.NewLine + Environment.NewLine + _
"The status of the requested license(s) is as follows:"
'get the status of the requested licenses.
sAvailability = AxLicenseControl1.get_LicenseAvailability(esriLicenseStatusOptions.esriLicenseStatusRequested).Split(Environment.NewLine)
For i = 0 To sAvailability.Length - 1
sFailure = sFailure + Environment.NewLine + sAvailability(i)
Next i
'Report failure to user.
System.Windows.Forms.MessageBox.Show(sFailure, "LicenseControl", MessageBoxButtons.OK)
'Programmatically shut down the application...
End If
[C#]
//If license initialization failed,
if (axLicenseControl1.Status != esriLicenseStatus.esriLicenseCheckedOut)
{
string failure = "License initialization failed for the following reason:" +
Environment.NewLine + axLicenseControl1.Summary + Environment.NewLine +
Environment.NewLine + "The status" +
"of the requested license(s) is as follows:";
//get the status of the requested licenses.
string[] availability = axLicenseControl1.get_LicenseAvailability
(esriLicenseStatusOptions.esriLicenseStatusRequested).Split
(Environment.NewLine.ToCharArray());
for (int i = 0; i <= availability.Length - 1; i++)
{
failure = failure + Environment.NewLine + availability[i];
}
//Report failure to user.
System.Windows.Forms.MessageBox.Show(failure, "LicenseControl",
MessageBoxButtons.OK);
//Programmatically shut down the application...
}
See Also:
LicenseControl ClassTo 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):
ESRI.ArcGIS.Controls ESRI.ArcGIS.System (ESRI.ArcGIS.esriSystem)
Development licensing | Deployment licensing |
---|---|
Engine Developer Kit | Engine Runtime |
ArcView | |
ArcEditor | |
ArcInfo |