[GIS] “Error HRESULT E_FAIL has been returned from a call to a COM component.” during using geoprocessor by VB.net

arcgis-10.0geoprocessingvb.net

I am also get a error shows like "Error HRESULT E_FAIL has been returned from a call to a COM component." And the Exception snapshot shows the "stacktrace" is at "ESRI.ArcGIS.Geoprocessing.GeoProcessorClass.Execute". Can you help me to solve it?

The thing is that I can using the geoprocessor by C#, but can't using it by vb.net. Is it something wrong with the setting or .NET framework?
Also, the Com Exception is -2147467259!

Private Sub RunBuffer()

    Dim gp As IGeoProcessor2 = New GeoProcessor()
    gp.OverwriteOutput = True
    Dim sev As Object = Nothing

    Try
        Dim parameters As IVariantArray = New VarArray()
        gp.AddToolbox("C:\Program Files (x86)\ArcGIS\Desktop10.0\ArcToolbox\Toolboxes\Data Management Tools.tbx")
        gp.SetEnvironmentValue("workspace", "C:\gp\AirportsAndGolf\golf.gdb")

        parameters.Add("C:\gp\AirportsAndGolf\golf.gdb\Airports")
        parameters.Add("C:\gp\AirportsAndGolf\golf.gdb\Airports_buff2")
        parameters.Add("1000 meters")

        gp.Execute("Buffer_analysis", parameters, Nothing)

       Console.WriteLine(gp.GetMessages(sev))

    Catch ex As Exception
        ' Print generic exception messages.
        Console.WriteLine(ex.Message)
        ' Print geoprocessing execution error messages.
        Console.WriteLine(gp.GetMessages(sev))
    End Try

End Sub

Best Answer

There are multiple Issues with your code.

Firstly, this is the old way of running Geoprocessing. You should Instead run Geoprocessing using the Managed Assembly. More Details are available in this document

Secondly, You should have correct Error Handling, which is also given in the above link.