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?

980
1
Jump to solution
09-15-2016 08:30 AM
ChristopherHeltzel
New Contributor II

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?

0 Kudos
1 Solution

Accepted Solutions
ChristopherHeltzel
New Contributor II

I found the definitive answer at this link http://resources.esri.com/help/9.3/arcgisdesktop/com/COM/IntroToCOM.htm

“The object classes within the ESRI object libraries do not implement the IDispatch interface; this means that these object libraries cannot be used with late-binding scripting languages, such as JavaScript or VBScript, since these languages require that all COM servers accessed support the IDispatch interface.”

Although I am not using a scripting language, the end result is the same: ArcObjects does not implement the IDispatch interface and therefore does not support late binding.

View solution in original post

1 Reply
ChristopherHeltzel
New Contributor II

I found the definitive answer at this link http://resources.esri.com/help/9.3/arcgisdesktop/com/COM/IntroToCOM.htm

“The object classes within the ESRI object libraries do not implement the IDispatch interface; this means that these object libraries cannot be used with late-binding scripting languages, such as JavaScript or VBScript, since these languages require that all COM servers accessed support the IDispatch interface.”

Although I am not using a scripting language, the end result is the same: ArcObjects does not implement the IDispatch interface and therefore does not support late binding.