[GIS] Unable to load DLL ‘ArcGISVersion.dll’: The specified module could not be found. (Exception from HRESULT: 0x8007007E)

arcgis-10.3arcgis-enginearcobjectsvisual studio

I recently migrated my desktop from ArcGIS 10.1 to 10.3.1 and visual studio from 2010 to 2013. I am now getting a problem trying to run an Engine application. It builds fine but when I try to debug it I get the above error. The error occurs right at the start when trying to get a list of installed environments "For Each item As ESRI.ArcGIS.RuntimeInfo In irs":

   Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup

        Dim irs As Generic.IEnumerable(Of ESRI.ArcGIS.RuntimeInfo)

        irs = ESRI.ArcGIS.RuntimeManager.InstalledRuntimes
        For Each item As ESRI.ArcGIS.RuntimeInfo In irs
            System.Diagnostics.Debug.Print(item.Path)
            System.Diagnostics.Debug.Print(item.Version)
            System.Diagnostics.Debug.Print(item.Product.ToString())
        Next
        Dim bInit As Boolean
        bInit = ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop)

    End Sub

From what I've read the problem is not that the ArcGISVersion.dll cannot be found (it imports into the solution no problem) it is that this .dll seems to call another .dll that cannot be found. The stack trace from the error is:

       at ESRI.ArcGIS.NativeInterop.DllGetClassObject(Guid& rclsid, Guid& riid, Object& ppv)

   at ESRI.ArcGIS.RuntimeManager.GetArcGISVersion()

   at ESRI.ArcGIS.RuntimeManager.<get_InstalledRuntimes>d__0.MoveNext()

   at SanGIS_RoadMaintenance.My.MyApplication.MyApplication_Startup(Objectsender, StartupEventArgs e) 
in R:\Work\Sangis\SanGISEditTools\SanGIS_RoadMaintenance\SanGIS_RoadMaintenance\Utilities\ApplicationEvents.vb:line 24

I'm not familiar with ESRI.ArcGIS.NativeInterop and I don't know how to add a reference to it.

Also I created a new ArcEngine project from scratch and that runs fine, no errors when debugging or binding to the license manager.

Does anybody know why this app might be failing after migration?

Best Answer

The problem was somehow the target CPU of the project had changed. If you go to project properties and then compile there are 2 places where the target platform is set. On the first line there is a dropdown for "Platform". This was correctly set to x86. But 4 rows down there is another drop down for "Target CPU". This was set to x64 somehow. Once I changed it to x86 it compiled fine. I don't know how this changed unless it was done automatically as part of the visual studio upgrade of the solution file from VS 2010 to VS 2013.

Anyway problem solved.