I am having an issue with our cost distance raster. I tried using our methods that worked in 10.0 to add these to the table of contents on the map to see the values returned. However when I all either
IApplication baseApp = (IApplication)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("E1740EC5-9513-11D2-A2DF-0000F8774FB5")));
or I call
IApplication baseApp = (IAplication)Activator.CreateInstance(Type.GetTypeFromProgID("esriFramework.AppRef"));
I get the same error returned :
Process Failed: System.Runime.InteropServices.COMException.....IClassFactory Failed due to error 8000ffff
I've seen discussions on Stack Overflow that you have to be inside an Arcmap enviroment....however I AM inside an Arcmap environment.
Is there a new way to do this inside 10.2.2 that these........developers didn't share with us???
Solved! Go to Solution.
One last idea: have you tried using the IAppROT (running object table) interface from the GP tool to get a hook to ArcMap? Lack of #CODE formatting in the new forums is a bummer, but here is an example of AppROT usage:
IAppROT appRot = new AppROTClass();
for (int i = 0; i < appRot.Count; i++)
{
if (appRot.Item.Name == "ArcMap")
{
IApplication arcMapApplication = appRotItem.Item as IApplication;
}
}
I don't believe you should be creating an instance of an IApplication; you should be getting a hook to an existing instance (that represents ArcMap itself).
Is your code inside of a custom ArcMap extension? If so, there should be an automatically generated ArcMap static class that exposes an Application property. Assuming this is true, the following code would work:
IApplicaiton baseApp = ArcMap.Application;
Activator.CreateInstance is how you get a hook into the singleton. I'm running a geoprocessing service as a tool inside Arcmap and as I said before I have done this without issues in ArcMap 10.0. It is now broken in 10.2.2
I follow you now.
There are a few variations on the code used to obtain a reference to the IApplication singleton, but nothing fundamentally different.
I am running 10.2.1 and both approaches work for getting a hook to the IApplication. Besides the ArcDesktop version difference, this code is running from an Add-In as opposed to a Tool.
Does your custom tool implement the ITool interface, or is it derived from BaseTool?
We implement our code using IGPFunction2 interface and the IGPFunctionFactory for exposing them to Arcmap.
One last idea: have you tried using the IAppROT (running object table) interface from the GP tool to get a hook to ArcMap? Lack of #CODE formatting in the new forums is a bummer, but here is an example of AppROT usage:
IAppROT appRot = new AppROTClass();
for (int i = 0; i < appRot.Count; i++)
{
if (appRot.Item.Name == "ArcMap")
{
IApplication arcMapApplication = appRotItem.Item as IApplication;
}
}
Wow! That worked! Nice of ESRi to force us to search for ways to get around their coding screwups.
Like I had nothing better to do.
BTW : Here is the code I implemented -- a bit different from what you did.
IAppROT appRot = new AppROTClass();
IApplication baseApp = null;
for (int index = 0; index< appRot.Count; index++)
{
if (appRot.get_Item(index) is ESRI.ArcGIS.Framework.AppRef)
baseApp = (IApplication)appRot.get_Item(index);
}
Thanks, Erin
Nice! I'm happy this worked for you.