System.InvalidCastException

Dec 29, 2011 at 8:11 AM
Edited Dec 29, 2011 at 8:13 AM

We have a windows application, with menu bar having ToolStripMenuItem called FEED DATA ENTRY which is a class inherited from User Control. We are adding this item into Menu bar using the following code

WorkItem.Parent.UIExtensionSites[UIExtensionSiteNames.MainMenu].Add<ToolStripMenuItem>(feedDataMgmt);

ToolStripMenuItem feedDataMgmt = new ToolStripMenuItem(MainMenuItems.FEEDDATAENTRY);

 

WorkItem.Parent.Commands[CommandNames.FeeddataEntry].AddInvoker(feedDataMgmt, "Click");

 

{try

{ FeedDataEntryForm feedform = new FeedDataEntryForm(); WindowWorkspace winWorkspace = new WindowWorkspace();

We have a command handler defined this way 

WorkItem.Parent.UIExtensionSites.RegisterSite(UIExtensionSiteNames.FeedDataEntryManagement, feedDataMgmt);

 

[CommandHandler(CommandNames.FeeddataEntry)]

 

 

public void OnFeedDataEntryClick(object sender, EventArgs e)  {if (WorkItem.SmartParts.Get<FeedDataEntryForm>(FEEDDATAENTRY_VIEW_ID) == null)WorkItem.SmartParts.Add(feedform, FEEDDATAENTRY_VIEW_ID);

winWorkspace.SmartPartClosing +=

 

new EventHandler<WorkspaceCancelEventArgs>(feedform.FeedDataEntryForm_FormClosing); winWorkspace.SmartPartActivated +=

 

new EventHandler<WorkspaceEventArgs>(feedform.OnUniflexCaseActivated);

winWorkspace.Show(feedform);Cursor.Current = Cursors.Default;}}catch (Exception objEx)

WorkItem.SmartParts.Remove(WorkItem.SmartParts.Get<FeedDataEntryForm>(FEEDDATAENTRY_VIEW_ID));

{Utility.ShowExceptionMessageBox(objEx, true);

 

I am getting Invalid Cast Exception when tried terminate the menuCommand

 

}

}

 

 

 

 

 

 Unable to cast object of type "FeedDataEntryForm' to type 'Microsoft.Practices.CompositeUI.Commands.Command'."

//Removing the Main Menu command handlers WorkItem

 menuCommandsWorkItem.Terminate();

 Please help me in resolving this bug