Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I got a strange issue in GP tool I don't really understand:

In my IGPFunction2.UpdateMessages() method, I use the following code to traverse all layers:

IEnumLayer enumLayer = gpUtils.GetMapLayers();
enumLayer.Reset();
ILayer layer = enumLayer.Next();
while (layer != null)
{
    <code here>
    layer = enumLayer.Next();
}

The purpose is to look for layers with duplicate names.

This works fine when I don't run the tool in the background. In background mode however, the Execute() method is never triggered.

This seems to happen after enumLayer.Next() is used. When removing the enumLayer.Next() and the code below, it works fine.

There are no error messages or exceptions occuring, and Arc claims that the tool executed succesfully. When calling IGPMessages.AddMessage() as the first action in Exceute(), nothing is yielded.

Any suggestions is appreciated..

share|improve this question
    
Can you create a minimal sample project and upload it somewhere? See this meta question for hosting suggestions. –  blah238 Feb 16 '13 at 15:43
    
Are you releasing COM object references? Might have something to do with it. I seem to remember this being particular important with enumerators. –  blah238 Feb 16 '13 at 15:44
    
Sure, I'll look into that when I get back to my office on monday. –  Oyvind Feb 16 '13 at 15:45
    
@blah238, good point! I'll try that when I get back to it. –  Oyvind Feb 16 '13 at 15:46
    
I'm using IGpMessages.Add() without any problems. I did have a problem but resolved it by instantiating a new IGpMessage instead of re-using. –  Kirk Kuykendall Feb 16 '13 at 18:50

1 Answer 1

up vote 1 down vote accepted

Resolved this when attaching the debugger to the background process.

For reasons I don't know, IGPUtilities.GetMapLayers() returns null when used inside UpdateMessages() right before Execute() is being triggered as a background job. This caused a NullPointerException to be thrown.

Still, ArcGis happily pretends that the tool succeeded in 2 seconds.

I work this around now by checking the return value from IGPUtilities.GetMapLayers().

share|improve this answer
    
I guess that makes sense. When you run a GP tool in the background it does not have access to the map AFAIK. –  blah238 Feb 18 '13 at 16:58
    
Sure, that would make sense if that code ran inside Execute(). I did the code in UpdateMessages(), which should not run in the background. The fact that I get "Tool succeeded" here is somewhat confusing. –  Oyvind Feb 18 '13 at 20:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.