Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm having problems trying to get a ICommand using the method ICommandBars.Find. The ICommand is there, but it's returning null to me.

Any ideas?

    public static ICommandItem GetCommandItemByName(string progId)
        UID uid = new UIDClass();
        uid.Value = progId;

        Type t = Type.GetTypeFromProgID("esriFramework.AppRef");
        object o = Activator.CreateInstance(t);

        IApplication application = o as IApplication;
        ICommandBars commandBars = application.Document.CommandBars;
        ICommandItem commandItem = commandBars.Find(uid,false,true);

        return commandItem;

The result is always null :(.

I need to get a reference to this specific command because it contains some fields and properties that I specified (a IWorkspace object, if it matters)

Thanks for your help!

share|improve this question
If you are developing an ArcGIS 10 add-in, you might have to fiddle with the onDemand attribute of the corresponding command definition in the Config.esriaddinx file. I can't remember whether it should be set to false or true, but IIRC that setting does make a difference. – stakx Feb 21 '12 at 16:14
up vote 5 down vote accepted

Hmm, that's interesting, seems like I remember this working differently before 10.0. I just did a test and even though the command is on a visible toolbar, another command was unable to find it. If I set noCreate to false it found it though.

At any rate, instead of having commands find each other, I recommend using an application extension to manage data that needs to be shared among command/tools. Each command would set a reference the extension in ICommand.Oncreate.

share|improve this answer
humn, this is very very puzzling. If i set noCreate to false the command gets duplicated :/. Darn, ArcObjects is fun but terrible when this sort of issue happens! I will look into App Extensions Kirk. Thanks. Actually Kirk, setting noCreate to false makes it work indeed and it did not duplicated my command on screen. 5th edit: actually this creates a brand new Icommand, though hidden, has different properties of the one on screen. argh! – George Aug 27 '10 at 20:18
Even if you get it figured out, there's still the risk that the same command might appear on some other toolbar somewhere. I guess you could find the toolbar, then loop through its commands. Still, I think an IExtension is the way to go. – Kirk Kuykendall Aug 27 '10 at 20:37
Humn, that is true. I'll look into it. Doesn't seem much work after all. – George Aug 27 '10 at 20:41
I suspect this might be related to the new addin architecture, where commands (and other components) are populated from the XML definitions, but instantiated in a delayed fashion, i.e. when they are first used, to improve applicaton startup time. Does the command you search for come from an addin? Even if it does not, chances are a similar mechanism (using some form of caching) has been newly employed for classical COM ICommands as well. – Petr Krebs Aug 30 '10 at 17:56

Just for the record.

I did implement my own extension, and since it's so ligthweight I did not bother to make configurable or a JIT extension.

It's a plain extension and it worked fine. Thanks for all the help.

share|improve this answer

Your Answer


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.