2

I'm wondering if I'm instantiating a new class with the IGeoProcessor2 object correctly. It's working the way I have it now, but I feel like there's something else I should be doing so I don't have to turn "Embed Interop Types" in the Properties window to False. I'm working with ArcObjects 10.5, ArcGIS 10.5, and Visual Studio 2015.

This is the code I have to instantiate a new geoprocessing object:

IGeoProcessor2 gp = new GeoProcessorClass();

If I leave the Esri.ArcGIS.Geoprocessing assembly's "Embed Interop Types" property on "True", I get a squiggly red line under GeoProcessorClass. If I set it to "False", the squiggly goes away and everything works as expected. The same thing also happens with the ESRI.ArcGIS.System assembly when I use this code:

IVariantArray parameters = new VarArrayClass();

If I were to set the "Embed Interop Types" to false for the System assembly then the squiggly under VarArrayClass goes away and everything works great.

Is this something everyone has to do to get their code to work, or am I missing something that allows me to keep "Embed Interop Types" as "True"?

I am using IGeoProcessor2 instead of GeoProcessor because I am running a custom tool out of a custom toolbox, so I cannot switch to GeoProcessor. For whatever reason, I cannot get it to work with my code.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jan 31, 2018 at 13:38

1 Answer 1

3

If 'Embed Interop Types' is set to true then omit the 'Class' at the end of the type.

IVariantArray parameters = new VarArray();
IGeoProcessor2 gp = new GeoProcessor() as IGeoProcessor2;
answered Jan 31, 2018 at 15:18
3
  • Hm, when I do, I get "cannot implicitly convert type 'ESRI.ArcGIS.Geoprocessing.GeoProcessor' to ESRI.ArcGIS.Geoprocessing.IGeoProcessor2'. An explicit conversion exists (are you missing a cast?)" warning. This only occurs for the GeoProcessor, the VarArray does work when I remove the class. Commented Jan 31, 2018 at 15:21
  • You just need to cast the new object to IGeoProcessor2. Some objects have implicit conversions others do not. Commented Jan 31, 2018 at 15:25
  • Thanks, I'm still new at this. IGeoProcessor2 gp = (IGeoProcessor2) new GeoProcessor(); worked. (I just saw you updated your answer, the "as" looks like a much cleaner way to type it. Great!) Commented Jan 31, 2018 at 15:27

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.