I am building a VSTO application (WinForms) and following the instructions at:
The steps are shown below:
- On the Project menu, click Add New Item.
- In the Add New Item dialog box, select Ribbon (XML).
- Change the name of the new Ribbon to MyRibbon, and click Add. The MyRibbon.cs or MyRibbon.vb file opens in the designer. An XML file that is named MyRibbon.xml is also added to your project.
- In Solution Explorer, right-click ThisAddin.cs or ThisAddin.vb, and then click View Code.
- Add the following code to the ThisAddin class. This code overrides the CreateRibbonExtensibilityObject method and returns the Ribbon XML class to the Office application.
When I add the CreateRibbonExtensibilityObject()
code in step 5 (shown below):
protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
{
return new MyRibbon();
}
I get the following error:
Cannot implicitly convert the type MyRibbon to Microsoft.Office.Core.IRibbonExtensibility. An explicit conversion exists (are you missing a cast)?
The class generated by Visual Studion is of type RibbonBase
.
partial class CLIREMPRibbon : Microsoft.Office.Tools.Ribbon.RibbonBase {...}
A type-cast below throws an exception:
Unable to cast object of type MyRibbon to type Microsoft.Office.Core.IRibbonExtensibility.
How would I apply the correct type cast of a RibbonBase to a IRibbonExtensibility interface instance?