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?
Solved! Go to Solution.
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.
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.