NullReference in WorkItemBuilder2


I'm not sure if it has to do with the fact that I've made it so some of the layout modules do not load immediately aftershellcreated but I was getting a NullReference error in the BuildCommandInfo method. When it tries to get the EventHandlers for a particular Command object it is possible that it returns a null value. I think in my case it is because there are a few CommandHandler which are instantiated way before there is a possibility for them to be used by any of the subscribers. I added the check for the Handlers being null.
Here are the lines which I changed:
if (Handlers != null)
            foreach (var item in Handlers.GetInvocationList())
                string name = item.Target.GetType().Name + " - " + item.Method.Name;
                h.Nodes.Add(name).Tag = item;