AnsweredAssumed Answered

Is it possible to create a standalone VB.Net desktop app using late binding of ArcObjects to avoid version dependencies that result from early binding?

Question asked by chrisheltzel on Sep 15, 2016
Latest reply on Sep 28, 2016 by chrisheltzel

I have a simple program that connects to a personal geodatabase to check various feature class properties.  Unfortunately the program cannot be installed on a client computer if it has a different version of ArcGIS Desktop than the one on my development computer (example: 10.3 on my computer and 10.2 or 10.4 on the client computer).  I want to use late binding so the OneClick installation does not fail due to a different ArcGIS version.

 

The following early binding code works, but is version dependent: 

 

Private Function OpenAccessWorkspace(ByVal sSourcePGDB as string) As ESRI.ArcGIS.Geodatabase.IWorkspace
   Dim aoFactory As IWorkspaceFactory   

   Dim aoWorkspace As IWorkspace

   aoFactory = New ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactory
   aoWorkspace = aoFactory.OpenFromFile(sSourcePGDB, 0)

   Return aoWorkspace
End Function

 

This late binding code fails at line 5 when setting aoWorkspace with error NullReferenceException: Object reference not set to an instance of an object.

 

Private Function OpenAccessWorkspace3(ByVal sSourcePGDB As String) As Object

   Dim aoFactory As Object

   Dim aoWorkspace As Object

   aoFactory = CreateObject("esriDataSourcesGDB.AccessWorkspaceFactory")
   aoWorkspace = aoFactory.OpenFromFile(sSourcePGDB, 0)       ' ERROR    

   Return aoWorkspace
End Function

 

Can anyone confirm that it is possible to use late binding with ArcObjects?  If so, can you tell what I am doing wrong?

Outcomes