2

Recently, I started having problems with my C# projects running ArcGIS10.1 geoprocessing tools. My tools point to custom scripts in project toolboxes. The code in question has run without issue in the past.

However, something in my environment has changed and even the simplest code throws errors. Please see sample below. The code fails on gp.Execute(). I've triple checked, labels, names, paths, parameters etc.

I've tried every thing I can think of to track down this problem including re-installing Arc. I'm dead in the water if I can't solve this nasty problem.

Thanks in Advance

    private void runTool()
    {
        try
        {

            Geoprocessor gp = new Geoprocessor();
            gp.AddToolbox(@"C:\0_Test\Test.tbx");

            IVariantArray parameters = new VarArrayClass();
            parameters.Add(@"MyStringArg");

            // Execute the tool.
            gp.Execute("test", parameters, null);

        }
        catch (Exception ex)
        {
            System.Windows.Forms.MessageBox.Show(ex.Message, "TestGP Error", System.Windows.Forms.MessageBoxButtons.OK);
            return;
        }
    }
  • Try this to debug further: put the offending code in a try block, and include a catch {COMException ce}. Then examine ce.ErrorCode. That gets you the 10-digit ArcObjects error code. Then you can try to find an ESRI document listing them all - good luck with that. Googling finds several of varying vintages, none complete - but you might get lucky. Or use the errlook.exe tool that is included with Visual Studio to look up the description for the error code. See help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/…. Best of luck! – MC5 Nov 6 '13 at 18:53
  • Thanks for the suggestion -- using the errlook.exe tool on -2147467259: too bad, turns out this is a generic "unspecified error". – David Plume Nov 6 '13 at 19:08
  • Have you tried looking at the GP messages, I usually find them more helpful then the actual COMException. – travis Nov 11 '13 at 8:39
1

Your method will only work for ESRI built-in tools. The reason it is failing is because you are trying to execute a custom tool.

Try this instead:

private void runTool()
{
    try
    {

        // Initialize the geoprocessor.
        IGeoProcessor2 gp = new GeoProcessorClass(); //USE IGEOPROCESSOR2 INSTEAD
        gp.AddToolbox(@"C:\0_Test\Test.tbx");

        IVariantArray parameters = new VarArrayClass();
        parameters.Add(@"MyStringArg");

        // Execute the tool.
        gp.Execute("test", parameters, null);

    }
    catch (Exception ex)
    {
        System.Windows.Forms.MessageBox.Show(ex.Message, "TestGP Error", System.Windows.Forms.MessageBoxButtons.OK);
        return;
    }
}

Also, see this link for some better ideas for troubleshooting geoprocessor errors.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.