none
Error when exiting Excel RRS feed

  • Question

  • I have a VS2010 VSTO Ribbon project. It is an Excel2007 project. When I run it I get no errors until I exit Excel. That is when I get the following error:

    System.InvalidCastException was unhandled
      Message=Unable to cast object of type 'System.EventArgs' to type 'Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs'.
      Source=Reporting
      StackTrace:
           at ElfInsight.Ribbon1._Lambda$__1(Object a0, EventArgs a1) in C:\Users\kds\Documents\Visual Studio 2010\Projects\RetailReporting\RetailReporting V0.19\Retail Reporting\Ribbon1.Designer.vb:line 0
           at System.ComponentModel.Component.Dispose(Boolean disposing)
           at System.ComponentModel.Component.Dispose()
           at Microsoft.Office.Tools.Ribbon.RibbonGroupImpl.Dispose(Boolean disposing)
           at System.ComponentModel.Component.Dispose()
           at Microsoft.Office.Tools.Ribbon.RibbonTabImpl.Dispose(Boolean disposing)
           at System.ComponentModel.Component.Dispose()
           at Microsoft.Office.Tools.Ribbon.OfficeRibbonImpl.Dispose(Boolean disposing)
           at System.ComponentModel.Component.Dispose()
           at Microsoft.Office.Tools.Ribbon.RibbonBase.Dispose(Boolean disposing)
           at ElfInsight.Ribbon1.Dispose(Boolean disposing) in C:\Users\kds\Documents\Visual Studio 2010\Projects\RetailReporting\RetailReporting V0.19\Retail Reporting\Ribbon1.Designer.vb:line 32
           at System.ComponentModel.Component.Finalize()
      InnerException:

    Line 32 of Ribbon1.Designer.vb is highlighted as BOLD:

    'Component overrides dispose to clean up the component list.
        <System.Diagnostics.DebuggerNonUserCode()> _
        Protected Overrides Sub Dispose(ByVal disposing As Boolean)
            Try
                If disposing AndAlso components IsNot Nothing Then
                    components.Dispose()
                End If
            Finally
                MyBase.Dispose(disposing)
            End Try
        End Sub

    I'm at a loss. Does anyone have any ideas?

    Regards

    Kerry

    Monday, July 30, 2012 3:57 AM

Answers

  • Hi,

    If you have too many code lines, please try to search these events including the signiture of Microsoft.Office.Tool.Ribbon.RibbonControlEventArgs in your code, for example,Private Sub Button1_Click(Byval sender As System.Object, Byval e As Microsoft.Office.Tool.Ribbon.RibbonControlEventArgs). If you are using a wrong signiture for such events, it may cause the exception. Then, change Microsoft.Office.Tool.Ribbon.RibbonControlEventArgs to System.EventArgs and try it again. Also, you can post the code including those events in the forum, and we will try to trouble shoot for you.

    Hope this can help you.

    Thanks,


    Leo_Gao [MSFT]
    MSDN Community Support | Feedback to us


    Tuesday, July 31, 2012 7:19 AM
    Moderator

All replies

  • Hi Kerry,

    Thanks for posting in the MSDN Forum.

    Based on the description of your issue, I assume that you may convert the Windows Form Control to the RibbonControl in your VSTO project. Please share more about your snippet in the forum for trouble shooting.

    Best Regards,


    Leo_Gao [MSFT]
    MSDN Community Support | Feedback to us


    Tuesday, July 31, 2012 6:02 AM
    Moderator
  • Hi Leo,

    Thanks for your reply.

    It very hard for me to say what I should share here. The error message doesn't tell me much and I have a fairly large project. It has a Ribbon with 2 tabs, 4 Custom Task Panes and 3 or 4 windows forms that open up at one point or another. Many thousands of lines. Can you point me to what part I should look at and post?

    Thanks Kerry

    Tuesday, July 31, 2012 6:23 AM
  • Hi,

    If you have too many code lines, please try to search these events including the signiture of Microsoft.Office.Tool.Ribbon.RibbonControlEventArgs in your code, for example,Private Sub Button1_Click(Byval sender As System.Object, Byval e As Microsoft.Office.Tool.Ribbon.RibbonControlEventArgs). If you are using a wrong signiture for such events, it may cause the exception. Then, change Microsoft.Office.Tool.Ribbon.RibbonControlEventArgs to System.EventArgs and try it again. Also, you can post the code including those events in the forum, and we will try to trouble shoot for you.

    Hope this can help you.

    Thanks,


    Leo_Gao [MSFT]
    MSDN Community Support | Feedback to us


    Tuesday, July 31, 2012 7:19 AM
    Moderator
  • Hi Leo,

    Thanks. That has resolved the error. I changed all signatures that included Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs to System.EventArgs and the error disappeared.

    The strange thing is that, if I add a control, say a button, to my ribbon and then double-click on it, it creates a click event with that signature as below.

    Private Sub Button1_Click(sender As System.Object, e As Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs) Handles Button1.Click

    Anyway it fixed my problem. Many thanks

    Kerry

    Tuesday, July 31, 2012 9:43 AM