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

Access Violation when opening VBE in SolidWorks #2195

Closed ThunderFrame closed 8 years ago

ThunderFrame commented 8 years ago

When opening the VBE in SolidWorks 2006-2007, I get an Access Violation:

Microsoft Visual Basic ................................................................................................................... 'Rubberduck' has caused an access violation.

Remove it from the list of available Add-Ins? ...................................................................................................................

VS Output:

'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\Andrew\Documents\GitHub\Rubberduck\RetailCoder.VBE\bin\Debug\Rubberduck.dll'. Symbols loaded.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\Andrew\Documents\GitHub\Rubberduck\RetailCoder.VBE\bin\Debug\NLog.dll'. Cannot find or open the PDB file.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel\v4.0_4.0.0.0__b77a5c561934e089\System.ServiceModel.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Serialization\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\Andrew\Documents\GitHub\Rubberduck\RetailCoder.VBE\bin\Debug\Ninject.dll'. Cannot find or open the PDB file.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\Andrew\Documents\GitHub\Rubberduck\RetailCoder.VBE\bin\Debug\Ninject.Extensions.Factory.dll'. Cannot find or open the PDB file.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\Andrew\Documents\GitHub\Rubberduck\RetailCoder.VBE\bin\Debug\Ninject.Extensions.Interception.DynamicProxy.dll'. Cannot find or open the PDB file.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\Andrew\Documents\GitHub\Rubberduck\RetailCoder.VBE\bin\Debug\Ninject.Extensions.Interception.dll'. Cannot find or open the PDB file.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\Andrew\Documents\GitHub\Rubberduck\RetailCoder.VBE\bin\Debug\Rubberduck.SettingsProvider.dll'. Symbols loaded.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.Vbe.Interop\15.0.0.0__71e9bce111e9429c\Microsoft.Vbe.Interop.dll'. Module was built without symbols.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\Andrew\Documents\GitHub\Rubberduck\RetailCoder.VBE\bin\Debug\Rubberduck.Parsing.dll'. Symbols loaded.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\WindowsBase\v4.0_4.0.0.0__31bf3856ad364e35\WindowsBase.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\Andrew\Documents\GitHub\Rubberduck\RetailCoder.VBE\bin\Debug\Castle.Core.dll'. Cannot find or open the PDB file.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'Microsoft.GeneratedCode'. 
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\Andrew\Documents\GitHub\Rubberduck\RetailCoder.VBE\bin\Debug\Rubberduck.VBEditor.dll'. Symbols loaded.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\Andrew\Documents\GitHub\Rubberduck\RetailCoder.VBE\bin\Debug\Rubberduck.SourceControl.dll'. Symbols loaded.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\PresentationCore\v4.0_4.0.0.0__31bf3856ad364e35\PresentationCore.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\Andrew\Documents\GitHub\Rubberduck\RetailCoder.VBE\bin\Debug\Rubberduck.SmartIndenter.dll'. Symbols loaded.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework\v4.0_4.0.0.0__31bf3856ad364e35\PresentationFramework.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xaml\v4.0_4.0.0.0__b77a5c561934e089\System.Xaml.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\Andrew\Documents\GitHub\Rubberduck\RetailCoder.VBE\bin\Debug\Ninject.Extensions.NamedScope.dll'. Cannot find or open the PDB file.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\Andrew\Documents\GitHub\Rubberduck\RetailCoder.VBE\bin\Debug\Antlr4.Runtime.net45.dll'. Cannot find or open the PDB file.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\Andrew\Documents\GitHub\Rubberduck\RetailCoder.VBE\bin\Debug\System.Windows.Interactivity.dll'. Cannot find or open the PDB file.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\Andrew\Documents\GitHub\Rubberduck\RetailCoder.VBE\bin\Debug\Ninject.Extensions.Conventions.dll'. Cannot find or open the PDB file.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'DynamicProxyGenAssembly2'. 
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'DynamicProxyGenAssembly2'. 
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\office\15.0.0.0__71e9bce111e9429c\office.dll'. Module was built without symbols.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'Anonymously Hosted DynamicMethods Assembly'. 
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Accessibility\v4.0_4.0.0.0__b03f5f7f11d50a3a\Accessibility.dll'. Cannot find or open the PDB file.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'DynamicProxyGenAssembly2'. 
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'DynamicProxyGenAssembly2'. 
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\CustomMarshalers\v4.0_4.0.0.0__b03f5f7f11d50a3a\CustomMarshalers.dll'. Cannot find or open the PDB file.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\WindowsFormsIntegration\v4.0_4.0.0.0__31bf3856ad364e35\WindowsFormsIntegration.dll'. Cannot find or open the PDB file.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\Andrew\Documents\GitHub\Rubberduck\RetailCoder.VBE\bin\Debug\Infralution.Localization.Wpf.dll'. Cannot find or open the PDB file.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework.Aero\v4.0_4.0.0.0__31bf3856ad364e35\PresentationFramework.Aero.dll'. Cannot find or open the PDB file.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework.Aero2\v4.0_4.0.0.0__31bf3856ad364e35\PresentationFramework.Aero2.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
2016-08-21 10:00:55.1036;TRACE;Rubberduck.UI.DockableToolwindowPresenter;Initializing Dockable Panel (CodeInspectionsDockablePresenter);
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework-SystemXmlLinq\v4.0_4.0.0.0__b77a5c561934e089\PresentationFramework-SystemXmlLinq.dll'. Cannot find or open the PDB file.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework-SystemXml\v4.0_4.0.0.0__b77a5c561934e089\PresentationFramework-SystemXml.dll'. Cannot find or open the PDB file.
2016-08-21 10:00:55.3938;TRACE;Rubberduck.UI.DockableToolwindowPresenter;Initializing Dockable Panel (TestExplorerDockablePresenter);
2016-08-21 10:00:55.7889;TRACE;Rubberduck.UI.SourceControl.SourceControlViewViewModel;Setting active tab to Changes;
2016-08-21 10:00:55.8306;TRACE;Rubberduck.UI.DockableToolwindowPresenter;Initializing Dockable Panel (SourceControlDockablePresenter);
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\UIAutomationTypes\v4.0_4.0.0.0__31bf3856ad364e35\UIAutomationTypes.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework-SystemData\v4.0_4.0.0.0__b77a5c561934e089\PresentationFramework-SystemData.dll'. Cannot find or open the PDB file.
2016-08-21 10:00:56.0480;TRACE;Rubberduck.UI.DockableToolwindowPresenter;Initializing Dockable Panel (ToDoExplorerDockablePresenter);
2016-08-21 10:00:56.3947;TRACE;Rubberduck.UI.DockableToolwindowPresenter;Initializing Dockable Panel (CodeExplorerDockablePresenter);
'sldworks.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\assembly\GAC\stdole\7.0.3300.0__b03f5f7f11d50a3a\stdole.dll'. Module was built without symbols.
A first chance exception of type 'System.AccessViolationException' occurred in Rubberduck.dll
ThunderFrame commented 8 years ago

SolidWorks 2006-2007 uses VBA 6.3, but so does Excel XP/2002 (and that works just fine with Rubberduck).

I do have to configure Solidworks to Run as Administrator, in order for it to run under Windows 10.

ThunderFrame commented 8 years ago

hmm, Access Violation seems to occur when assigning the button images/masks:

If I step over the assignments, Rubberduck loads without error.

        public static void SetButtonImage(CommandBarButton button, Image image, Image mask)
        {
            button.FaceId = 0;
            if (image == null || mask == null)
            {
                return;
            }

            try
            {
                //BOTH OF THESE ASSIGNMENTS CAUSE ACCESS VIOLATIONS
                button.Picture = AxHostConverter.ImageToPictureDisp(image);
                button.Mask = AxHostConverter.ImageToPictureDisp(mask);
            }
            catch (COMException exception)
            {
                Logger.Debug("Button image could not be set for button [" + button.Caption + "]\n" + exception);
            }
        }

I found a couple of KB articles: 286460 - How To Set the Mask and Picture Properties for Office XP CommandBars

The Mask and Picture properties are defined as type IPictureDisp, which is a member of the Stdole library. IPictureDisp uses methods that cannot be marshalled across process boundaries. Therefore, the Mask and Picture properties can only be called in-process (VBA macros, Automation Add-ins, and ActiveX DLLs run in-process).

As previously stated, the IPictureDisp interface cannot be marshalled across process boundaries. Attempts to set the Picture and Mask properties out-of-process result in the following error:

Run-time error '-2147418113(8000ffff)': Method 'Picture' of object '_CommandBarButton' failed

Therefore, you cannot set these properties for a CommandBarButton from any out-of-process Automation client or from an in-process component that is running in debug mode in the Visual Basic IDE. If you run the sample Add-in described in this article from the Visual Basic IDE, you will receive this error. To avoid the error while debugging, you can comment the lines that set the Picture and Mask properties or use conditional compilation, such as an #If...Then...#Else directive.

288771 - How To Create a Transparent Picture For Office CommandBar Buttons

Office XP offers a new Picture and Mask property for CommandBarButtons. This allows in-process clients (such as macro code or a COM Add-In) to directly assign a StdPicture object to the button without using the clipboard. However, due to limitations outside of Office, this technique does not work for out-of-process Automation clients, nor does it work for clients that need to remain compatible with earlier versions of Office.

ThunderFrame commented 8 years ago

http://stackoverflow.com/questions/39061559/how-can-i-pre-emptively-determine-if-accessing-a-property-will-cause-an-accessvi

Vogel612 commented 8 years ago

Is this fixed with #2196 ?

retailcoder commented 8 years ago

If the diagnosis was correct (which I don't doubt), it should be.