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.92k stars 302 forks source link

Unhandle Exception .Net Framework #4767

Open SmileyFtW opened 5 years ago

SmileyFtW commented 5 years ago

Version 2.4.0.4488 OS: Microsoft Windows NT 10.0.17134.0, x64 Host Product: Microsoft Office x86 Host Version: 16.0.11231.20130 Host Executable: EXCEL.EXE

Got this upon closing Excel: unhandledexception

The text in the details: UnhandledExceptionText.txt

Vogel612 commented 5 years ago

The underlying reason seems to be a disconnected COM RCW Wrapper:

System.Runtime.InteropServices.InvalidComObjectException: COM object that has been separated from its underlying RCW cannot be used.
   at System.StubHelpers.StubHelpers.GetCOMIPFromRCW(Object objSrc, IntPtr pCPCMD, IntPtr& ppTarget, Boolean& pfNeedsRelease)
   at Microsoft.Vbe.Interop._VBProject.get_References()
   at Rubberduck.VBEditor.SafeComWrappers.VBA.VBProject.get_References() in C:\projects\rubberduck\Rubberduck.VBEditor.VBA\SafeComWrappers\VB\VBProject.cs:line 45
   at Rubberduck.Navigation.CodeExplorer.CodeExplorerProjectViewModel.GetProjectReferenceModels() in C:\projects\rubberduck\Rubberduck.Core\Navigation\CodeExplorer\CodeExplorerProjectViewModel.cs:line 150
   at Rubberduck.Navigation.CodeExplorer.CodeExplorerProjectViewModel.SynchronizeReferences() in C:\projects\rubberduck\Rubberduck.Core\Navigation\CodeExplorer\CodeExplorerProjectViewModel.cs:line 117
   at Rubberduck.Navigation.CodeExplorer.CodeExplorerProjectViewModel.AddNewChildren(List`1& updated) in C:\projects\rubberduck\Rubberduck.Core\Navigation\CodeExplorer\CodeExplorerProjectViewModel.cs:line 100
   at Rubberduck.Navigation.CodeExplorer.CodeExplorerItemViewModel.SynchronizeChildren(List`1& updated) in C:\projects\rubberduck\Rubberduck.Core\Navigation\CodeExplorer\CodeExplorerItemViewModel.cs:line 73
   at Rubberduck.Navigation.CodeExplorer.CodeExplorerProjectViewModel.Synchronize(List`1& updated) in C:\projects\rubberduck\Rubberduck.Core\Navigation\CodeExplorer\CodeExplorerProjectViewModel.cs:line 87
   at Rubberduck.Navigation.CodeExplorer.CodeExplorerViewModel.<>c__DisplayClass46_0.<Synchronize>b__0() in C:\projects\rubberduck\Rubberduck.Core\Navigation\CodeExplorer\CodeExplorerViewModel.cs:line 263
   at Rubberduck.Parsing.UIContext.UiDispatcher.<>c__DisplayClass2_0.<InvokeAsync>b__0(Object x) in C:\projects\rubberduck\Rubberduck.Parsing\UIContext\UiDispatcher.cs:line 28

We currently only have an issue pertaining to powerpoint open with this error: #4757

MDoerner commented 5 years ago

This has been introduced with the PR bringing the reference nodes to the CE. The problem is that it is still trying to get the reference information from the VBE when we are already in the shutdown.

bclothier commented 5 years ago

I would say the source of the problem comes from this:

https://github.com/rubberduck-vba/Rubberduck/blob/4e1844a568445a9ef6675aa96c2401b231bf9031/Rubberduck.Core/Navigation/CodeExplorer/CodeExplorerViewModel.cs#L217-L245

We start to turn off the event pipeline via this:

https://github.com/rubberduck-vba/Rubberduck/blob/5af7fed2dc4eadf7d5f2867287b22efda0020b3a/Rubberduck.Main/Extension.cs#L257

into:

https://github.com/rubberduck-vba/Rubberduck/blob/5af7fed2dc4eadf7d5f2867287b22efda0020b3a/Rubberduck.VBEEditor/Events/VBENativeServices.cs#L41-L54

The problem, though is that the RPS does not currently listen to the Terminate event:

https://github.com/rubberduck-vba/Rubberduck/blob/5af7fed2dc4eadf7d5f2867287b22efda0020b3a/Rubberduck.Parsing/VBA/RubberduckParserState.cs#L203-L211

It probably needs to start listening to it and use it to cancel the current parse & stop broadcasting its own events.

daFreeMan commented 5 years ago

Not sure if this is related or not, but I'll post as additional info:

Had an XLSM open with the VBE open and the project parsed (.4533). Opened an XLSX RD parsed (the VBE was in the background) Got the JIT debugging info.

dotNET Framework error.txt RubberduckLog.txt

JNurick commented 5 years ago

Have just had the same or similar, twice on successive RubberDuck refreshes. Excel had been open for an hour or two doing desultory editing of code and code-behind-form modules, running code to test. After clicking Continue on the .NET dialog, refreshing seemed to complete normally. Restarting Excel appears to have made the problem go away.

RubberDuck Version 2.4.1.4627 OS: Microsoft Windows NT 10.0.17134.0, x64 Host Product: Microsoft Office x86 Host Version: 16.0.11425.20202 Host Executable: EXCEL.EXE

.NET error details in attached file. DotNet RCW exception 20190411.txt

JNurick commented 5 years ago

Same again, though Excel had been open, mostly idle, for much longer. Please let me know if there's anything more helpful I can do next time.

Version 2.4.1.4627 OS: Microsoft Windows NT 10.0.17134.0, x64 Host Product: Microsoft Office x86 Host Version: 16.0.11425.20204 Host Executable: EXCEL.EXE

DotNet RCW exception 20190417.txt

1stZedd commented 1 year ago

Same as others, I am not sure when this started but I think it was after Windows 11 upgrade.

After using Excel and going into 'Visual Basic' from the 'Developer' Tab, RubberDuck add-on starts up. I can continue as normal, but when exiting Excel I get an 'Unhandled exception' error. image Clicking on the 'Details' button show the following: Excel exit error RubberDuck.txt

Clicking 'Continue' closes the error, but Excel is left running in the background unusable. Another instance can not be started until the process is terminated with Task Manager.

This error condition was happening with v2.5.2.1 (main) and is happening with Prerelease-v2.5.2.6260 (next).

This error condition does not happen if I don't go to 'Visual Basic'. This error condition does not happen with RubberDuck uninstalled.

I hope that this is enough information needed but if not don't hesitate to ask.

Thanks