In my VB.NET application, I am using ArcObjects 10.4 and I am initializing ArcGIS. I load a feature class from a shapefile. The problem is that I get an HRESULT error 0x80040228, which is 2147220952 in decimal and it means "License not intialized" as you can see on this website: http://resources.arcgis.com/en/help/arcobjects-net/componenthelp/index.html#//0025000000mn000000
The strange thing is, I load two feature classes. One from a shapefile, then another from a file geodatabase. As I said, loading from the shapefile crashes, but not from the FGDB. Also, if I invert the two LoadFeatureLayer lines, the FGDB feature class loads, and then, the shapefile feature class loads too. I tried with different features classes, the result is the same.
Is it a normal behavior?
Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.Geodatabase
Imports ESRI.ArcGIS.esriSystem
Public Class frm_Loading
Public aoInit As IAoInitialize
Private Sub frm_Loading_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
InitializeArcGIS()
LoadFeatureLayer("export_output_2.shp", "c:\temp")
LoadFeatureLayer("C_R137_CH", "c:\temp\FGDB.gdb", True)
End Sub
Public Sub InitializeArcGIS()
If aoInit Is Nothing Then
If ESRI.ArcGIS.RuntimeManager.ActiveRuntime Is Nothing Then
ESRI.ArcGIS.RuntimeManager.BindLicense(ESRI.ArcGIS.ProductCode.Desktop)
End If
aoInit = New AoInitialize
aoInit.Initialize(esriLicenseProductCode.esriLicenseProductCodeBasic)
End If
End Sub
Public Function LoadFeatureLayer(ByVal layer As String, ByVal cheminWorkspace As String, Optional FGDB As Boolean = False) As IFeatureLayer
Dim aWorkspaceFactory As IWorkspaceFactory = Nothing
Dim aFeatureWorkspace As IFeatureWorkspace = Nothing
Dim aFeatureLayer As IFeatureLayer
Try
If FGDB Then
Dim t As Type = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory")
Dim obj As System.Object = Activator.CreateInstance(t)
aWorkspaceFactory = obj
Else
Dim t As Type = Type.GetTypeFromProgID("esriDataSourcesFile.ShapefileWorkspaceFactory")
Dim obj As System.Object = Activator.CreateInstance(t)
aWorkspaceFactory = obj
End If
aFeatureWorkspace = aWorkspaceFactory.OpenFromFile(cheminWorkspace, 0)
aFeatureLayer = New FeatureLayer
aFeatureLayer.FeatureClass = aFeatureWorkspace.OpenFeatureClass(layer)
aFeatureLayer.Name = aFeatureLayer.FeatureClass.AliasName
Return aFeatureLayer
Catch ex As Exception
Debug.Print(ex.ToString)
Return Nothing
Finally
If aWorkspaceFactory IsNot Nothing Then System.Runtime.InteropServices.Marshal.FinalReleaseComObject(aWorkspaceFactory)
If aFeatureWorkspace IsNot Nothing Then System.Runtime.InteropServices.Marshal.ReleaseComObject(aFeatureWorkspace)
End Try
End Function
End Class