Unspecified error when running the Buffer tool.

455
5
Jump to solution
08-14-2012 07:41 AM
GeorgeFaraj
Occasional Contributor III
Hello,

I'm getting the following exception thrown when trying to run a Geoprocessing tool:

"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



The code I'm using is:

  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();   }


I'm only testing the Buffer tool currently. I've checked, and the tool has both the in_features and out_feature_class assigned correctly before running the process. Any clues?

Thanks,
George Faraj
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor
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.

View solution in original post

0 Kudos
5 Replies
KenBuja
MVP Esteemed Contributor
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.
0 Kudos
GeorgeFaraj
Occasional Contributor III
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.


I tried specifying it using the following:

tool.buffer_distance_or_field = "500 METERS";


and

tool.buffer_distance_or_field = 150;


I'm still getting the same exception being thrown. Since I'm using the ArcGIS Runtime Engine, I can't see the results in the ArcMap application.

Any other ideas? Thanks for the help!
0 Kudos
KenBuja
MVP Esteemed Contributor
You should add some code to see what the messages in your results variable contain. Here's how I have it in one of my applications.

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
0 Kudos
GeorgeFaraj
Occasional Contributor III
Apparently, it's a problem if the output file already exists. It works if I specify a file name that doesn't exist. Thanks for all the help!
0 Kudos
KenBuja
MVP Esteemed Contributor
If you don't need to worry about overwriting a file, you can set the IGeoprocessor::OverwriteOutput property to true.
0 Kudos