Bug fix request

Hi;

There is one bug I hope gets fixed in Office 12. (Fixing it in a service pack for Office 9 - 11 would be really nice too.)

Sometimes the menus I add to Word stop calling my event handlers. A very easy way to see this happen is open two instances of Word, close the first instance of Word, then close the document (but not Word itself) of the second instance.

The menu objects will now fault if you access the enabled property and they will no longer call the event handlers for the menus.

thanks - dave


Answer this question

Bug fix request

  • PCZ

    Hi;

    I'm not disagreeing with you. I was already doing what you suggested. I just want to make sure MS fixes it so there are no exceptions thrown when code is running normally. My worry is they will leave it as is.

    thanks - dave

  • hologram

    Hi David

    You say that you have two instances of word are they seperate processes in Task Manager do you have two WINWORD.EXE's as this is impossible as they are two independant solutions and in effect dont share events so you are losing the event handler for a different reason, I have never expierienced this but do have a complex set of code to handle the menu bars to ensure I have a collection to handle these controls.

    Regards

  • andreskruse

     DavidThi808 wrote:
    My problem is that my variable holding the menu is not null.
    It was not null in my case as well.  If it points to a Word CommandBar, you just re-seat it, as my code shows.
    The null case in my code was triggered when the code was invoked during initialization, when I had to create it the first time.
     DavidThi808 wrote:
    Is there a property in it I can check
    Not that I know of.
    You could wrap it in a try/catch block and expect an exception if it goes south (COMException, I believe) but I found that just preemptively re-seating it solves the problem.

    Try it.  It's as simple as "myToolbar = commandBars[MyId]" and it solved the problem for me.


  • Dencore

     DavidThi808 wrote:
    10) Call CommandBarPopup.Enabled = false; on menu item that is in a menu added to the main Word menu. It will throw an exception.
    Ah, this one sounds familiar.

    If your CommandBarPopup is kept in a variable, it can get disconnected from the actual command bar instance.

    My guess is that Word caches the command bars and then gives us a handle to the cached instance, which becomes invalid when the cache is flushed (or something like that).

    Anyway, the following code snippet solved the problem for me:

    // Create or re-create the ToolBar
    Office.CommandBars commandBars = app.CommandBars;
    if (myToolbar == null)
    {
      myToolbar = commandBars.Add(TOOLBAR_TAG,
                                  Office.MsoBarPosition.msoBarTop,
                                  false, true);
    }
    else
    {
      // Get it from Word in case it was flushed
      myToolbar = commandBars[TOOLBAR_TAG];
    }

     


    I think I mentioned something about it in the newsgroup but I am not sure.



  • AnandMVP

    Hi;

    I am doing that, I have my access in a try/catch and if the exception is thrown, I re-apply these and then it works.

    However, it is bad programming for an exception to be thrown when code is operating "normally". It's not just that the code is then slow, but it signifies an error condition. I run under the debugger with it set to break if a handled exception is caught so I make sure I catch any errors.

    And finally, it is a bug and therefore should be fixed. If Word gives us an object to a menu item, it should either stay good, or there should be an event telling us if we need to re-apply them.

    My $0.02 worth - thanks - dave

  • Arty Arochita

    Hi Dave,

    Interesting, I don't recall encountering such behaviour in our add-in.

    Are you sure that your controls do not get garbage collected


  • GavinG

    Yep, positive. I did have that when I first wrote it but the garbage collection takes it out in 5 - 20 seconds. This very clearly occurs after closing the document - and my copies of the controls are still there.

    Also, after a long Long LONG argument with MS tech support on this where they kept insisting there was no bug, they finally tried it and then agreed that it is a bug.

    Try the steps I listed with your Add-In.

    thanks - dave

  • kingofnexus

    Hi;

    My problem is that my variable holding the menu is not null. Is there a property in it I can check

    thanks - dave

  • crazy

    Hi;

    To verify I am doing this right, I do the following.
    1) In my IDTExtensibility2 derived class I have a member variable that is created when the IDTExtensibility2 object is created.
    2) That variable has two member variables, a CommandBarPopup[5] that is the menu I insert in the main Word toolbar and the 4 menus in the drop down menu from that that have child menus. And I have a CommandBarControl[24] that is all the menus that have events tied to them.
    3) I create all of these menus when the object is first created.
    4) On various events I enable/disable some of these menus.
    5) One event is the DocumentChange event that gets fired when a document is closed. When this happens I disable a lot of the menus. This is when the bug occurs.

    - thanks - dave

  • DaveyC11111

     DavidThi808 wrote:
    Try the steps I listed with your Add-In.

    1. Click on Word icon in Quick Launch bar (1st Word window opens with blank document, add-in loads)
    2. Click on Word icon in Quick Launch bar (2nd Word window opens with blank document, add-in already loaded)
    3. Close 1st Word window
    4. Close blank document in 2nd Word window
    5. Click on add-in specific menu and select an item.

    Works fine.


  • Magic Hat 9

    It's harder to hit now - they may have made it better. Here's how I can get it to occur:

    1) Launch debugger which brings up word.
    2) Open document A in that instance of Word.
    3) From that same instance of Word, open document B - which starts another instance of Word.
    4) Close instance of Word with document A
    5) Close document (not Word) with document B
    6) Open document A in running instance of Word
    7) From running instance of Word, open document B
    8) Close instance of Word with document A
    9) Close document (not Word) with document B
    10) Call CommandBarPopup.Enabled = false; on menu item that is in a menu added to the main Word menu. It will throw an exception.

    The menu item is a ComObject and is still in scope. But accessing any of it's members in the debugger displays "an exception was thrown"

    If I just start Word with a document I can edit it for hours without this problem. It's the closing/opening documents/Word that does it.

    thanks - dave

    ps - I provided my code once before to MS to reproduce this bug. But if they think it is now fixed, I am happy to do so again.


  • Peterleex

     DavidThi808 wrote:
    Hi;

    I am doing that, I have my access in a try/catch and if the exception is thrown, I re-apply these and then it works.

    However, it is bad programming for an exception to be thrown when code is operating "normally". It's not just that the code is then slow, but it signifies an error condition. I run under the debugger with it set to break if a handled exception is caught so I make sure I catch any errors.

    And finally, it is a bug and therefore should be fixed. If Word gives us an object to a menu item, it should either stay good, or there should be an event telling us if we need to re-apply them.

    My $0.02 worth - thanks - dave

    Dave,

    You can wait for Microsoft to fix this bug or you can do what I did and code around it.

    I did not come here to argue with you.  If my suggestions do not help you then don't use them.

    Best regards,
    Alex.

  • Bug fix request