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.88k stars 299 forks source link

Rubberduck does not work with Autodesk Inventor 2020 #5373

Open BACEjackson opened 4 years ago

BACEjackson commented 4 years ago

Rubberduck version information The info below can be copy-paste-completed from the first lines of Rubberduck's log or the About box:

Version 2.5.0.5244 OS: Microsoft Windows NT 6.1.7601 Service Pack 1, x64 Host Product: Microsoft Office x64 Host Version: 16.0.12325.20344 Host Executable: EXCEL.EXE (Does not open in Inventor.exe)

Description A clear and concise description of what the bug is. I get the following pop-up when opening VBA:

Title: Rubberduck Add-In could not be loaded Pop-Up Body: Rubberduck's startup sequence threw an unexpected exception. Please check the Rubberduck logs for more information and report an issue if necessary.

To Reproduce Steps to reproduce the behavior:

  1. Start Autodesk Inventor.
  2. Open the VBA Editor.
  3. Error:

Expected behavior A clear and concise description of what you expected to happen.

Rubberduck to open as it does for all other applications including Autodesk AutoCAD 2020.

Screenshots If applicable, add screenshots to help explain your problem.

Logfile Rubberduck generates extensive logging in TRACE-Level. If no log was created at %APPDATA%\Rubberduck\Logs, check your settings. Include this log for bug reports about the behavior of Rubberduck.

Logfile did not generate but generates through other applications.

Additional context Add any other context about the problem here.

Vogel612 commented 4 years ago

Without more information what exactly goes wrong this is going to be really hard to diagnose. To my knowledge no currently active contributor has Autodesk Inventor 2020 available...

Your best bet to get this fixed is to download Visual Studio 2019 and run a debug yourself to find out more about the way startup failed. If you need any pointers towards setting up a debug build, this wiki page should be a good start.

danny-boy-online commented 4 years ago

I confirm the same problem as OP with the VBE shipped with Inventor but I believe it might be because Inventor starts the VBE with a reference to the "Autodesk Inventor Object Library" that Rubberduck does not like.

I also confirm the same issue is experienced on previous versions of Autodesk Inventor Professional - i installed/uninstalled 2016, 2017 and 2020 - they all reproduce the undesirable behaviour.

I am on Win10 PC.

I confirm that aside from this issue with the Autodesk Inventor Object Library that Rubberduck is working well for me in Office365 Excel 32bit and Excel 64bit (i experimented with installing/uninstalling both just to see).

I confirm that Rubberduck works well for me in Excel until I add a reference to the "Autodesk Inventor Object Library" (RxInventor.tbl file). Even with trivial code that makes no actual use of the added reference (and compiles ok) Rubberduck will always yield "Resolver Error" when I refresh. E.g. trivial code in Module1:

Option Explicit
Public Sub Test()
    Debug.Print "do nothing at all"
End Sub

Removing the reference from the project makes Rubberduck work again.

I attach the trace for when i click refresh just after adding the Autodesk Inventor Object Library reference:

RubberduckLog - After.txt

Hope this helps someone. Pity cos i was looking forward to using Rubberduck . regards Dan

bclothier commented 4 years ago

That is very helpful! By any chance, do you have either oleview (requires Visual Studio) or olewoo (can be downloaded)? I'd love to get the IDL for that library which may provide additional clues.

danny-boy-online commented 4 years ago

bclothier - Yes I have oleview. Attached is the RxInventor.tbl file. Inventor ships with these two in the respective 'bin' and 'bin32' folders. The VBA IDE seems to detect the one it wants depending on whether your Excel install is 32 or 64 bit.

Inventor 2020.zip

bclothier commented 4 years ago

You can do that, too. I did not suggest that initially because of licensing concerns. Some companies don't like sharing DLLs even if they are useless without the rest of the product. If you choose to do that, we can download & remove once we get it.

danny-boy-online commented 4 years ago

Attached IDL file as requested.

RxInventor.IDL.txt

bclothier commented 4 years ago

Awesome! That is very helpful. As soon as I am able, I will do some testing with the TLB/IDL files and see what might be causing it to fault.

retailcoder commented 4 years ago

For the record, the reason the resolver is throwing an exception here, is to avoid needing to deal with the consequences of a resolver pass that wouldn't have access to all the declarations available in referenced libraries - every single constant defined in the failing-to-load library would be treated as an undeclared variable in user code; a lot of inspections would be issuing a TON of false positives, and then types and members of a referenced library would be treated like user code, so Rubberduck would merrily allow you to rename things, which would obviously further break the code: nothing good can ever come out of a failed resolver pass, so rather than lighting things up and letting users shoot themselves in the foot with a bazooka, we report an error state and basically turn into a brick until a successful parse completes all steps.

We've had COM libraries throwing various COM exceptions before - and every time we get a new one, our COM library loader gets more & more precise and fail-safe, so @danny-boy-online thanks A LOT for providing these files!

danny-boy-online commented 4 years ago

@retailcoder - glad it was helpful. :) Is there an alert list i can subscribe to for this fix so that my colleagues and myself can return to download Rubberduck when it is useable with Inventor?

Vogel612 commented 4 years ago

@danny-boy-online you can watch this repository for new releases (or just watch it in general). Note that every pull request we merge gets a prerelease, so it might be a few notifications, before it works.

As it is, you should be automatically notified when this issue gets closed, because you commented here :)

bclothier commented 4 years ago

Update: I just loaded up a new Excel workbook, added some fluff code, added the reference to bin\rxinventor.tlb and it was able to parse & resolve the project.

I tried adding:

Public Sub doit()
    Dim x As Inventor.AddInAutomation
    Dim y As Inventor.Document

    Debug.Print "hi"
End Sub

and it still resolves. :\

I tried the bin32\rxinventor.tlb just to make sure it wasn't being weird but was unable to load (which I expect since Excel is 64-bit).

Can you please confirm that this issue exists even with the latest version of Rubberduck?

bclothier commented 4 years ago

I also noticed that there's a definition for an add-in object. Is it the case that when you load Excel, you also have a Inventor add-in available to you in either Excel or VBA addins (note those are 2 separate kinds of add-ins, with separate managers; so we need to check both places). It might actually be the add-in that is causing problem. We can verify this by unloading the add-in from the add-in manager then reference the library only. If it resolves, then the problem is definitely with the add-in.

danny-boy-online commented 4 years ago

Update: I just loaded up a new Excel workbook, added some fluff code, added the reference to bin\rxinventor.tlb and it was able to parse & resolve the project. ... Can you please confirm that this issue exists even with the latest version of Rubberduck?

@bclothier - the OP and I are using the latest official release 2.5.0.5244. Which version are you using so that i can download and try the one you are using and report back pls?

Vogel612 commented 4 years ago

You are using the latest green release, @bclothier is most likely referring to the latest prerelease, which is v2.5.0.5338. You can find that release at our "full" list of releases

danny-boy-online commented 4 years ago

there's a definition for an add-in object. Is it the case that when you load Excel, you also have a Inventor add-in available to you in either Excel or VBA addins (note those are 2 separate kinds of add-ins, with separate managers; so we need to check both places). It might actually be the add-in that is causing problem. We can verify this by unloading the add-in from the add-in manager then reference the library only. If it resolves, then the problem is definit

@bclothier - i don't think so. Attached are screenshots and you can see that I have no VBA and no EXCEL AddIns loaded except for RD.

AddIns_COM AddIns_EXCEL AddIns_VBA

danny-boy-online commented 4 years ago

@Vogel612 , @bclothier I've updated RD to the latest you recommended (v2.5.0.5338) . I still get the same error as you can see in screenshot. AddIns_VBA_LatestPrerelease

retailcoder commented 4 years ago

Good news, repro confirmed on x64!

Version 2.5.0.5244
OS: Microsoft Windows NT 6.1.7601 Service Pack 1, x64
Host Product: Microsoft Office x64
Host Version: 16.0.12430.20264
Host Executable: EXCEL.EXE

Now the bad news is, I don't have a RD debug build on this machine, so I'm not sure exactly what's going on with the resolver, but I can confirm that removing the .tlb reference makes the parse run to completion.

From the logs and stack trace it looks like the .tlb was successfully loaded though. This needs further investigation.

2020-02-19 20:37:46.3219;TRACE-2.5.0.5244;Rubberduck.Parsing.VBA.ComReferenceLoading.COMReferenceSynchronizerBase;Loading referenced type 'Inventor'.;
2020-02-19 20:37:47.5977;INFO-2.5.0.5244;Rubberduck.Parsing.Common.ParsingStageTimer;Loaded and unloaded referenced libraries in 1324ms.;
retailcoder commented 4 years ago

Repro also confirmed with the latest pre-release built (x64):

Version 2.5.0.5338
OS: Microsoft Windows NT 6.1.7601 Service Pack 1, x64
Host Product: Microsoft Office x64
Host Version: 16.0.12430.20264
Host Executable: EXCEL.EXE

Steps taken:

retailcoder commented 4 years ago

Something isn't adding up. According to logs this switch block is where the exception comes from:

public IExpressionBinding BuildTree(Declaration module, Declaration parent, IParseTree expression, IBoundExpression withBlockVariable, StatementResolutionContext statementContext, bool requiresLetCoercion = false, bool isLetAssignment = false)
{
    switch (expression)
    {
        case VBAParser.LExpressionContext lExpressionContext:
            return Visit(module, parent, lExpressionContext);
        case VBAParser.ExpressionContext expressionContext:
            return Visit(module, parent, expressionContext);
        case VBAParser.AddressOfExpressionContext addressOfExpressionContext:
            return Visit(module, parent, addressOfExpressionContext);
        default:
            throw new NotSupportedException($"Unexpected context type {expression.GetType()}");
    }
}

However the claimed "unexpected context type" is VBAParser.ExpressionContext. The question becomes "how the heck did VBAParser.ExpressionContext not match the case VBAParser.ExpressionContext branch, ....and that defies logic in a pretty scary way (we're using pattern matching in quite a lot of places).

bclothier commented 4 years ago

On the other hand, I have not been able to reproduce, even using the steps that @retailcoder outlined. image

There is a possibility that the problem is with something outside the Rubberduck that bites the ducky in its rear (e.g. a certain framework version with a buggy implementation of pattern matching).

retailcoder commented 4 years ago

Adding the logged stack trace from my repro:

2020-02-20 10:59:28.1631;TRACE-2.5.0.5338;Rubberduck.Common.LogLevelHelper;
    Rubberduck version 2.5.0.5338 loading:
    Operating System: Microsoft Windows NT 6.1.7601 Service Pack 1 x64
    Host Product: Microsoft Office x64
    Host Version: 16.0.12430.20264
    Host Executable: EXCEL.EXE;
...
2020-02-20 11:00:11.0691;WARN-2.5.0.5338;Rubberduck.Parsing.VBA.ReferenceManagement.CompilationPasses.TypeAnnotationPass;Failed to resolve type VBE;
2020-02-20 11:00:11.4531;ERROR-2.5.0.5338;Rubberduck.Parsing.VBA.ReferenceManagement.ReferenceResolveRunnerBase;Exception thrown on resolving those modules: 'VBAProject.Module1' (thread 20).;System.NotSupportedException: Unexpected context type Rubberduck.Parsing.Grammar.VBAParser+ExpressionContext
   à Rubberduck.Parsing.Binding.TypeBindingContext.BuildTree(Declaration module, Declaration parent, IParseTree expression, IBoundExpression withBlockVariable, StatementResolutionContext statementContext, Boolean requiresLetCoercion, Boolean isLetAssignment) dans C:\projects\rubberduck\Rubberduck.Parsing\Binding\TypeBindingContext.cs:ligne 35
   à Rubberduck.Parsing.Binding.TypeBindingContext.Resolve(Declaration module, Declaration parent, IParseTree expression, IBoundExpression withBlockVariable, StatementResolutionContext statementContext, Boolean requiresLetCoercion, Boolean isLetAssignment) dans C:\projects\rubberduck\Rubberduck.Parsing\Binding\TypeBindingContext.cs:ligne 20
   à Rubberduck.Parsing.Binding.BindingService.ResolveType(Declaration module, Declaration parent, ParserRuleContext expression) dans C:\projects\rubberduck\Rubberduck.Parsing\Binding\BindingService.cs:ligne 49
   à Rubberduck.Parsing.VBA.ReferenceManagement.CompilationPasses.TypeAnnotationPass.AnnotateType(Declaration declaration) dans C:\projects\rubberduck\Rubberduck.Parsing\VBA\ReferenceManagement\CompilationPasses\TypeAnnotationPass.cs:ligne 74
   à Rubberduck.Parsing.VBA.ReferenceManagement.CompilationPasses.TypeAnnotationPass.Execute(IReadOnlyCollection`1 modules) dans C:\projects\rubberduck\Rubberduck.Parsing\VBA\ReferenceManagement\CompilationPasses\TypeAnnotationPass.cs:ligne 38
   à System.Collections.Generic.List`1.ForEach(Action`1 action)
   à Rubberduck.Parsing.VBA.ReferenceManagement.ReferenceResolveRunnerBase.ExecuteCompilationPasses(IReadOnlyCollection`1 modules, CancellationToken token) dans C:\projects\rubberduck\Rubberduck.Parsing\VBA\ReferenceManagement\ReferenceResolveRunnerBase.cs:ligne 144
2020-02-20 11:00:11.4701;DEBUG-2.5.0.5338;Rubberduck.Parsing.VBA.RubberduckParserState;Module 'Module1' state is changing to 'ResolverError' (thread 20);
2020-02-20 11:00:11.4701;INFO-2.5.0.5338;Rubberduck.Parsing.VBA.RubberduckParserState;RubberduckParserState (21) is invoking StateChanged (ResolverError);
2020-02-20 11:00:11.6751;INFO-2.5.0.5338;Rubberduck.Parsing.Common.ParsingStageTimer;Executed compilation passes in 990ms.;
2020-02-20 11:00:11.6751;INFO-2.5.0.5338;Rubberduck.Parsing.Common.ParsingStageTimer;Added supertypes for document modules in 0ms.;
2020-02-20 11:00:11.6751;DEBUG-2.5.0.5338;Rubberduck.Parsing.VBA.ReferenceManagement.ReferenceResolveRunnerBase;Resolving identifier references in 'VBAProject.Module1'... (thread 20);
2020-02-20 11:00:11.6751;DEBUG-2.5.0.5338;Rubberduck.Parsing.VBA.ReferenceManagement.ReferenceResolveRunnerBase;Binding resolution done for component 'VBAProject.Module1' in 0ms (thread 20);
2020-02-20 11:00:11.6751;DEBUG-2.5.0.5338;Rubberduck.Parsing.VBA.RubberduckParserState;Module 'Module1' state is changing to 'Ready' (thread 20);
2020-02-20 11:00:11.6751;INFO-2.5.0.5338;Rubberduck.Parsing.Common.ParsingStageTimer;Resolved references in 1ms.;

Attached, logged file from Dan. RubberduckLog.txt

danny-boy-online commented 4 years ago

@retailcoder - any luck with this? Do you need me to send any more dll's or anything?

sirKitKat commented 4 years ago

I'll just mention it here also: there is a trail version of Autodesk Inventor that can be used for 30 days. The VBA component is available in every license version (Pro/standard)

ls-2037 commented 2 years ago

Using Inventor 2018, this is fixed in the latest development version (2.5.2.6030). However, issue #5913 occurs.

ls-2037 commented 1 year ago

Broken in Inventor 2020 using latest Rubberduck. Same error as this bug, and no logs are produced.

The code explorer loads and works but the menu item is not added to the top bar or to the right-click context menu, so it is impossible to access the Rubberduck settings.