Can I use Activator.CreateInstance when declaring a new Geoprocessor object??

3676
16
06-16-2010 08:09 AM
JoshV
by
Regular Contributor
I've used the below lines of code to start creating a new geodatabase but I need to do something similar for declaring a new Geoprocessor object.  I keep getting an error in my C# code right at Geoprocessor gp = new Geoprocessor.  I'm guessing this is because of the new keyword so I'm hoping I can use something similar to below code

Type t = Type.GetTypeFromProgID("esriDataSourcesGDB.AccessWorkspaceFactory.1");//("{DD48C96A-D92A-11D1-AA81-00C04FA33A15}");
                    System.Object obj = Activator.CreateInstance(t);
16 Replies
JoshV
by
Regular Contributor
Just in case I'm wrong and the new keyword is not the issue, here is the error I'm getting at Geoprocessor gp = new Geoprocessor();

Creating an instance of the COM component with CLSID {5374EC4C-1AA2-4829-A811-DE624ECEC23F} from the IClassFactory failed due to the following error: 80010105
0 Kudos
StefanOffermann
Deactivated User
I am developing ArcMap extensions quite frequently, but it was never a problem to create an instance in C# with the new keyword. May be you are developing an ArcGIS engine application? In this case, I would try to check out a license before instantiating the geoprocessor object.

http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//00010000043p000000

The Geoprocessor is not listed, so using the Activator class is not the right way.

Best regards, Stefan
0 Kudos
JoshV
by
Regular Contributor
I am developing ArcMap extensions quite frequently, but it was never a problem to create an instance in C# with the new keyword. May be you are developing an ArcGIS engine application? In this case, I would try to check out a license before instantiating the geoprocessor object.

http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//00010000043p000000

The Geoprocessor is not listed, so using the Activator class is not the right way.

Best regards, Stefan


I'm using a Standalone C# console application so using the activator class was correct nearly everywhere I had to replace a "new" keyword.  I have already used aoinitialize to checkout a license.  If you know of any other suggestions please let me know.

Thanks
0 Kudos
NeilClemmons
Honored Contributor
Below is the code from a Windows service that I wrote a while back.  I fully qualified the class names to avoid confusion with the old Geoprocessor class in the Geoprocessing library.

            ESRI.ArcGIS.ConversionTools.FeatureClassToFeatureClass fcToFcTool = new ESRI.ArcGIS.ConversionTools.FeatureClassToFeatureClass();
            fcToFcTool.in_features = featureLayer;
            fcToFcTool.out_path = outputDirectory;
            fcToFcTool.out_name = newTableName;
            if (!string.IsNullOrEmpty(query))
                fcToFcTool.where_clause = query;

            Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
            gp.Execute(fcToFcTool, null);
0 Kudos
JoshV
by
Regular Contributor
Below is the code from a Windows service that I wrote a while back.  I fully qualified the class names to avoid confusion with the old Geoprocessor class in the Geoprocessing library.

            ESRI.ArcGIS.ConversionTools.FeatureClassToFeatureClass fcToFcTool = new ESRI.ArcGIS.ConversionTools.FeatureClassToFeatureClass();
            fcToFcTool.in_features = featureLayer;
            fcToFcTool.out_path = outputDirectory;
            fcToFcTool.out_name = newTableName;
            if (!string.IsNullOrEmpty(query))
                fcToFcTool.where_clause = query;

            Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
            gp.Execute(fcToFcTool, null);


Hi Neil-  Thanks for the response.  I have used nearly the same exact code before in my other functions and not got an error but for some reason I am still getting that IClassFactory error even if I use the fully qualified geoprocessor name.  Any suggestions?
0 Kudos
KirkKuykendall
Deactivated User
Creating an instance of the COM component with CLSID {5374EC4C-1AA2-4829-A811-DE624ECEC23F} from the IClassFactory failed due to the following error: 80010105


Sounds like this might be an install issue ... if you search your registry, do you find this key?

If not, consider re-installing.
0 Kudos
JoshV
by
Regular Contributor
Sounds like this might be an install issue ... if you search your registry, do you find this key?

If not, consider re-installing.


Hi Kirk-

I did a search in my registry and found that key in esriGeoprocessing.GeoProcessor.   This is puzzling.. Thoughts?
0 Kudos
KirkKuykendall
Deactivated User
Here's the key I have (on Vista64):
HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{5374EC4C-1AA2-4829-A811-DE624ECEC23F}

Do you have this key (or its 32 bit equivalent) ?

Does this code work for you?
public static void TestGp()
{
    Guid g = new Guid("5374EC4C-1AA2-4829-A811-DE624ECEC23F");
    Type t = Type.GetTypeFromCLSID(g);
    Debug.Print(t.ToString());
    GeoProcessor gp = Activator.CreateInstance(t) as GeoProcessor;
    Debug.Print(gp.OverwriteOutput.ToString());
    
}
0 Kudos
JoshV
by
Regular Contributor
Here's the key I have (on Vista64):
HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{5374EC4C-1AA2-4829-A811-DE624ECEC23F}

Do you have this key (or its 32 bit equivalent) ?

Does this code work for you?
public static void TestGp()
{
    Guid g = new Guid("5374EC4C-1AA2-4829-A811-DE624ECEC23F");
    Type t = Type.GetTypeFromCLSID(g);
    Debug.Print(t.ToString());
    GeoProcessor gp = Activator.CreateInstance(t) as GeoProcessor;
    Debug.Print(gp.OverwriteOutput.ToString());
    
}


Hi Kirk-

2 questions: What is the GUI for the Geoprocessor object not GeoProcessor?  I was using Geoprocessor object because its execute method only takes 2 arguments.

If I have to use GeoProcessor then the first parameter required is string Name.  What is Name?  The Name of the tool?  FeatureClassToFeatureClass_Conversion?
0 Kudos