rubberduck-vba / Rubberduck

Every programmer needs a rubberduck. COM add-in for the VBA & VB6 IDE (VBE).
https://rubberduckvba.com
GNU General Public License v3.0
1.91k stars 299 forks source link

Sometimes I get a COMException when I first launch VBE #720

Closed zippy1981 closed 9 years ago

zippy1981 commented 9 years ago

Sometimes I get a COM exception the first time I hit ALT+F11 and i don't have all the RubberDuck right click menu items untill I restart excel.exe. Is there any way I can get more debug data when that happens?

rubberduck203 commented 9 years ago

Do you have a solid way to reproduce?

zippy1981 commented 9 years ago

Start excel hit alt+F11 sometimes it happens. It hasn't happened since a mandated reboot. I'll play around with it some more.

PetLahev commented 9 years ago

This remains me similar error in my add-in Going to VBE editor while application is opening causes errors with menu Haven't looked at it yet (as it's now almost replaced by the great ducky add-in :) ) but it may give you some idea how it may happen

retailcoder commented 9 years ago

I can't get a repro on this. Excel 2013 x64.

zippy1981 commented 9 years ago

Cross referencing this comment. Would you accept a patch with polly?

rubberduck203 commented 9 years ago

I'd rather get to the absolute root of the issue, but I'd consider an acceptable patch. I believe it has to do with the toolwindow not properly being torn down in certain situations. I think maybe, and it an awful big maybe, that information about the custom toolwindow is stored in the registry, so, when first launching the plugin, the VBE tries to restore the toolwindows, but the custom ones don't exist yet. I've not tested that theory yet because the simple retry has worked for me at all times.

Do us a favor and shut off/temporarily uninstall your other addins @zippy1981. Let's see if there's not another conflict between addins going on before you write a patch.

zippy1981 commented 9 years ago

I actually disabled Blockspring (and all my other addins were disabled as well) and the problem didn't go away after multiple excel restarts. I can try rebooting later.

Your probably right that multiple retries aren't the answer. No code comments or commit comments indicated why there was a try/catch. When I get the com addin to show up again, I can certainly debug things some more with Visual Studio, process monitor. and whatever other tools I can find to shed light on COM exceptions.

rossknudsen commented 9 years ago

@zippy1981 I'm jumping in at the end of a conversation and may show my ignorance here. But since you seem keen to perform some investigation yourself, I'll give you some ideas on what you could try.

RD mentioned that the ComException HResult code is &H80004005. Googling leads me to this page. This sounds reasonable, since this class provides the functionality for hosting content in a toolwindow and uses subclassing.

So I reckon try adding a external call to InitCommonControls could be worth trying (see this). I'm not sure where this call needs to go and whether it needs to be called repeatedly or once at application startup.

zippy1981 commented 9 years ago

Worth a shot.

zippy1981 commented 9 years ago

The issue seems to be that ParserErrorsPresenter is initiated twice. One in the App constructor, and once in Setup. commenting it out in App doesn't seem to break anything. Should that be the fix?

jsmuise commented 9 years ago

I'm trying to use this addin with outlook 2010 and when I try to use the addin the following error is logged in the event viewer

Log Name: Application Source: .NET Runtime Date: 10/08/2015 6:36:38 PM Event ID: 1026 Task Category: None Level: Error Keywords: Classic User: N/A Computer: WIN-1LD3MK33CKC Description: Application: OUTLOOK.EXE Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: System.NullReferenceException Stack: at System.Runtime.InteropServices.Marshal.ReleaseComObject(System.Object) at Rubberduck.VBEditor.VBEHost.HostApplicationBase`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].Finalize()

Event Xml:

1026 2 0 0x80000000000000 3013 Application WIN-1LD3MK33CKC Application: OUTLOOK.EXE Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: System.NullReferenceException Stack: at System.Runtime.InteropServices.Marshal.ReleaseComObject(System.Object) at Rubberduck.VBEditor.VBEHost.HostApplicationBase`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].Finalize() any ideas on what causes this?
zippy1981 commented 9 years ago

Open a separate issue @mention me there. Can you attach outlook to visual studio and point the debugger to the rubber duck source code and see where that exception gets thrown?

rubberduck203 commented 9 years ago

@jsmuise what are you trying to do when you get this error? If I had to guess I'd say you're trying to run unit tests. Can you confirm please?

Vogel612 commented 9 years ago

as of the list available under https://github.com/rubberduck-vba/Rubberduck/issues/112 , Outlook is not supporting unit-tests yet (possibly because Application.Run is not supported)

retailcoder commented 9 years ago

From the stack trace @jsmuise gave us, I would be tempted to blame this code:

    ~HostApplicationBase()
    {
        Marshal.ReleaseComObject(Application);
    }

ReleaseComObject will throw a NullReferenceException when its argument is null, which is also compatible with the stack trace shown.

This would fix it:

    ~HostApplicationBase()
    {
        if (Application != null)
        {
            Marshal.ReleaseComObject(Application);
        }
    }

I'm in the middle of huge structural changes in my own fork, so I'll create an issue and tag it with [up-for-grabs]. (update: see #744)

@Vogel612 that's exactly the reason why Outlook can't run unit tests :wink:

retailcoder commented 9 years ago

I'm closing this issue, since I couldn't get a repro with 1.4.x, #732 and #744 have been dealt with, and v2.0 introduces a completely different startup paradigm.