1

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

closed as off-topic by Vince, Jochen Schwarze, whyzar, nmtoken, neogeomat Jan 31 at 0:15

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This problem cannot or can no longer be reproduced. Changes to the system or to the asker's circumstances may have rendered the question obsolete, or the question does not include a procedure to enable potential answerers to reproduce the same symptoms. Such questions are off-topic as they are unlikely to help future readers, but editing them to include more details can lead to re-opening." – Vince, Jochen Schwarze, whyzar, nmtoken, neogeomat
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    If you can create a WorkspaceFactory then I would expect your license is working. What line actually throws the exception when it fails? Also try removing the '.shp' from your call to LoadFeatureLayer. – danielm Jan 29 at 16:47
  • The error happens at the line aWorkspaceFactory.OpenFromFile. I also tried to remove the SHP and it changes nothing. – Math Jan 29 at 18:14
  • I have tested and run your code and run it without any issues (shapefile first). Have you tested any other shapefiles? ArcMap does give unrelated error messages from time to time. – danielm Jan 29 at 18:43
  • I tested other shapefiles and it doesn't work. But I have just tested it on a machine with ArcGIS 10.2 and it works. It feels like a ArcGIS 10.4 problem. I will try other 10.4 machines and if it is still not working, I will send this case to ESRI. Thank you! – Math Jan 29 at 19:50

Browse other questions tagged or ask your own question.