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!

onDemandattribute of the corresponding command definition in theConfig.esriaddinxfile. I can't remember whether it should be set tofalseortrue, but IIRC that setting does make a difference. – stakx Feb 21 '12 at 16:14