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

3218
16
06-16-2010 08:09 AM
JoshV
by
Occasional 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
KirkKuykendall
Occasional Contributor III
What is the GUI for the Geoprocessor object not GeoProcessor?

Please elaborate.
0 Kudos
JoshV
by
Occasional Contributor
Please elaborate.


what is the GUID for Geoprocessor?  for GoeProcessor you are saying it is {5374EC4C-1AA2-4829-A811-DE624ECEC23F}.  But I'm wondering for Geoprocessor (lower case p).
0 Kudos
JoshV
by
Occasional Contributor
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?


That worked Kirk.  I used the below code and it worked for inserting my FC into SDE.  It still baffles me as to why it fails otherwise but I'll stick with what works.  Thanks Kirk and Neil.  I wish I could give you guys points somehow like in the old forums..


                    IVariantArray vp = new VarArrayClass();
                    vp.Add(in_Features);
                    vp.Add(out_path);
                    vp.Add(out_name);


                    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;
                    gp.Execute("FeatureClassToFeatureClass", vp, null);
0 Kudos
JoshV
by
Occasional Contributor
Kirk, Neil, or anyone that can help.. I was wrong about my last post and I am not getting this to work consistently.  I still get the IClassFactory error at times when I try to run a Geoprocessing tool like CreateFileGDB, etc.  What is so WEIRD is that sometimes I get this error and sometimes it works.  Please let me know if you know what I can do here.
0 Kudos
KirkKuykendall
Occasional Contributor III
Are you creating it repeatedly in a loop?

Did you try calling Marshal.ReleaseCOMobject on it once you're finished with it?
0 Kudos
JoshV
by
Occasional Contributor
Are you creating it repeatedly in a loop?

Did you try calling Marshal.ReleaseCOMobject on it once you're finished with it?



Hi Kirk-  Great to hear your quick reply.  I'm not using it in a loop but I tried GC.Collect()  I will try the Marshall method you mentioned.  I have maybe 30 functions and about 10 of them use the Geoprocessor gp = new Geoprocessor();  I also tried your method which I believe is using GeoProcessor (capital P).  Once one of these functions throws that "IClassFactory error" then the other functions that use Geoprocessor throw that error too.  So you are thinking that C# program is not getting rid of the object properly?  Or what is your explanation?  I'm still learning 😉
0 Kudos
JoshPritt
New Contributor III

I'm having the exact same issue with my windows console EXE in C# for 10.2.1.3497 - even the part where it works sometimes but not every time!  Some times it works just fine. Others it fails with that same error: 

Creating an instance of the COM component with CLSID {5374EC4C-1AA2-4829-A811-DE624ECEC23F} from the IClassFactory failed due to the following error: 80010105.System.Runtime.InteropServices.COMException (0x80010105): Creating an instance of the COM component with CLSID {5374EC4C-1AA2-4829-A811-DE624ECEC23F} from the IClassFactory failed due to the following error: 80010105.

   at ESRI.ArcGIS.Geoprocessor.Geoprocessor..ctor()

I'm checking out an Advanced license at the beginning so that part is working fine.

I'm referencing the following .net assemblies:

ESRI.ArcGIS.Geoprocessing

C:\Program Files (x86)\ArcGIS\DeveloperKit10.2\DotNet\ESRI.ArcGIS.Geoprocessing.dll

runtime v2.0.50727

version 10.2.0.0

ESRI.ArcGIS.Geoprocessor

C:\Program Files (x86)\ArcGIS\DeveloperKit10.2\DotNet\ESRI.ArcGIS.Geoprocessor.dll

runtime v2.0.50727

version 10.2.0.0

Here's my code (it fails right on that first line when executing that Geoprocessor() constructor):

Geoprocessor GP = new Geoprocessor();

IGeoProcessorResult processorResult = null;

var createFileGDBTool = new CreateFileGDB(exportFolder, fileGdbName);
processorResult = (IGeoProcessorResult)GP.Execute(createFileGDBTool, null);

var gpTool = new FeatureClassToFeatureClass(inputtable, fullExportPath, fileGdbTableName) { };
processorResult = (IGeoProcessorResult)GP.Execute(gpTool, null); ‍‍‍‍‍‍‍‍‍

Why in the world would it work sometimes and not every time?

0 Kudos