"Error HRESULT E_FAIL has been returned from a call to a COM component." at ESRI.ArcGIS.Geoprocessing.GeoProcessorClass.Execute(String Name, IVariantArray ipValues, ITrackCancel pTrackCancel) at ESRI.ArcGIS.Geoprocessor.Geoprocessor.ExecuteInner(IGPProcess process, ITrackCancel trackCancel, IGeoProcessor igp, IVariantArray iva) at ESRI.ArcGIS.Geoprocessor.Geoprocessor.Execute(IGPProcess process, ITrackCancel trackCancel) at GisViewer.GeoprocessingDialog.<RunSelectedTool>b__0() in C:\TASource\Source\MRA\PACS.NET-1.0\GisViewer\Dialogs\GeoprocessingDialog.cs:line 154
private IFeatureLayer GetSelectedLayers() { foreach (String item in featureList.CheckedItems) { for (int i = 0; i < synchronizer.MapControl.LayerCount; ++i) { var layer = synchronizer.MapControl.get_Layer(i); if (layer.Name == item) { return layer as IFeatureLayer; } } } return null; } private IGPProcess GetSelectedTool() { var selectedTool = (GeoprocessorCommand.Command)toolCombo.SelectedItem; if (selectedTool == GeoprocessorCommand.Command.Buffer) { var tool = new ESRI.ArcGIS.AnalysisTools.Buffer(); tool.in_features = GetSelectedLayers(); tool.out_feature_class = outputText.Text; return tool; } else if (selectedTool == GeoprocessorCommand.Command.Clip) { var tool = new ESRI.ArcGIS.AnalysisTools.Clip(); return tool; } else if (selectedTool == GeoprocessorCommand.Command.Dissolve) { //var tool = new ESRI.ArcGIS.AnalysisTools. //return tool; } else if (selectedTool == GeoprocessorCommand.Command.Intersect) { var tool = new ESRI.ArcGIS.AnalysisTools.Intersect(); return tool; } else if (selectedTool == GeoprocessorCommand.Command.Merge) { //var tool = new ESRI.ArcGIS.AnalysisTools //return tool; } else if (selectedTool == GeoprocessorCommand.Command.Union) { var tool = new ESRI.ArcGIS.AnalysisTools.Union(); return tool; } return null; } private void RunSelectedTool() { new Thread(new ThreadStart( delegate() { var processor = new Geoprocessor(); var tool = GetSelectedTool(); if (tool != null) { try { var results = (IGeoProcessorResult)processor.Execute(tool, null); if (results.Status == ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded) { for (int i = 0; i < results.OutputCount; ++i) { var outputVal = results.GetOutput(i); if (outputVal is DEFeatureClass) { } } } } catch (Exception) { MessageBox.Show("There was an error while running the geoprocessor", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } )).Start(); }
Solved! Go to Solution.
One of the required properties you have to set for the Buffer tool is the buffer_distance_or_field, either a value or a numeric field. I don't see that property being assigned in your code. Also, when getting an error with one of the geoprocessing tools, the first thing I do is check the results window in ArcMap. It usually tells me why the tool has failed.
tool.buffer_distance_or_field = "500 METERS";
tool.buffer_distance_or_field = 150;
Dim Result As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2 Dim ErrorMessage As String Result = CType(GP.Execute(Process, Nothing), ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2) If Result.Status <> ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded Then If Result.MessageCount > 0 Then For Count As Integer = 0 To Result.MessageCount - 1 ErrorMessage += Result.GetMessage(Count) Next System.Windows.Forms.MessageBox.Show(ErrorMessage, "Geoprocessor failed") End If End If