3

I've created a custom form that has a couple buttons and a Text box.

This custom form is opened by a click event button I have created on a Microsoft outlook add-in that I am working on attached to a 'Ribbon'. (Not sure if this matters, no problem here).

On the windows form, The first button simply saves the contents of the text file to disk.

The other button attempts to close the form. In this buttons click event I have tried the following two lines, separate and together

this.Close(); and this.Dispose();

When I use this button or the Form exit (the 'x' located in the upper right of a windows form) I receive the follow error,

COMException was unhandled by user Exception from HRESULT: 0x800A01A8

When this error is thrown, it takes me to the 'Connect.cs' files following method,

public void OnBeginShutdown(ref System.Array custom)
        {

            this.toolbarButton.Delete(System.Reflection.Missing.Value);
            this.toolbarButton = null;

        }

I'm not sure how to begin troubleshooting this. I have done a fair amount of research but unfortunately haven't found much. I'm sure the problem might be the fact I have created a custom form with no experience and there are some 'housekeeping' or 'best practices' that I have not done or are aware of.

Anyone have insight into this?

Jodrell
  • 34,946
  • 5
  • 87
  • 124
Bryan Harrington
  • 991
  • 2
  • 17
  • 31
  • This code will bomb when it runs *twice*. Not entirely unlikely since Form.Close() normally already includes a dispose. Add `if (this.toolbarButton != null)` to be safe. – Hans Passant Aug 28 '12 at 18:22

1 Answers1

0

I'm guessing a little here but that HResult for a COMException means Object Required, So, when you are calling CommandBarButton.Delete one of two things is wrong.

Either you have already disposed the button instance or you should be passing true or false to the Delete call.

The button shouldn't be disposed until after it has been removed from the toolbar, and when it is disposed you may need to do a Marshal.ReleaeComObject to dereference it properly.

Community
  • 1
  • 1
Jodrell
  • 34,946
  • 5
  • 87
  • 124