Geoprocessing COMException when running my own script.

730
3
07-04-2012 11:12 AM
magdakosior
New Contributor II
Hi,
I have searched a lot of forums looking for answers but none have helped so far. 
I am trying to run my own script ( a dummy empty one for now) with geoprocessing in Visual studio 2010 using c# and ArcDesktop 10.  When I ran this with the "Buffer_analysis" built in tool and some different parameters it worked fine.  When I run my own script (which i know it sees as i print the tools out) i can't even get gp.GetMessage(0) error messages, they just come up blank.

Here is my c#.net code:
using ESRI.ArcGIS.Geoprocessing;

GeoProcessor gp = new GeoProcessor();

ESRI.ArcGIS.esriSystem.AoInitialize ao = null;
try
{
    RuntimeManager.Bind(ProductCode.Desktop);
    ao = new AoInitializeClass();
    esriLicenseStatus licStatus = ao.Initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);  //Ive also tried arcEditor liscence
    ao.CheckOutExtension(esriLicenseExtensionCode.esriLicenseExtensionCode3DAnalyst);
    Debug.WriteLine("License Checkout successful.");

gp.OverwriteOutput = true;
gp.AddToolbox(@"C:\MyToolbox.tbx");

IGpEnumList tools = gp.ListTools("*");
string tool = tools.Next();
while (tool != "")
{
     Debug.WriteLine(tool);
     tool = tools.Next();
}
IVariantArray parameters = new VarArrayClass();
parameters.Add(@"C:\Custom_Menu\shape.shp");
gp.Execute("test", parameters, null);//*********************************this gives the error***************************************
...
}
catch... Debug.WriteLine(gp.GetMessage(0))



Here is my "test.py" script:

# Import arcpy module
import arcpy, os
from arcpy import env

arcpy.AddMessage( "\nDone")


I don't get it.  Please help...
0 Kudos
3 Replies
DietmarPalmetzhofer
New Contributor III
I am having the same problem. Did you ever solve it?
Thanks,
Didi
0 Kudos
DietmarPalmetzhofer
New Contributor III
Found the solution:
* use the name of the tool in the properties->general tab, and not the label in the toolbox
* use a an IVariantArray paramter, even if there are no parameters.

Solution found here:
http://forums.arcgis.com/threads/28884-Execute-Custom-Tool-Obeject-Reference-Not-Set-for-instance-of...
0 Kudos
magdakosior
New Contributor II
I did resolve it though I can't point it to a specific thing that I changed.  My code looks pretty much the same but with a lot of testing I realized that somewhere along the line I lost the ability to run this in debug mode (as in it fails right away when it hits gp.execute).  When I deploy it and run it as a tool it seems to work fine.  I also had some issues working with scripts off a network drive (versus the C drive). 
The one thing that I can recommend is to be meticulous about the number of parameters being passed in and the amount that the script expects. If all fails try to re-write the script from a new empty file and to make sure that the script runs fine on its own.

Oh yah and I noticed that instead of using GeoProcessor I later used Geoprocessor (with a small p).  One is geoprocessing and one is geoprocessor.

Good luck.

I am having the same problem. Did you ever solve it?
Thanks,
Didi
0 Kudos