Exceptions in SolidWorks generated macro code

I am getting exceptions in the automatically generated code in a VSTA macro. The code is:

Private Sub SolidWorksMacro_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup

        Me.swApp = Me.SolidWorksApplication
        Dim runResult As SolidWorks.RunMacroResult = RunMacro()
        If (runResult = SolidWorks.RunMacroResult.NoneSpecified) Then
            Try
                SwMacroSetup()
            Catch exSetup As Exception
                System.Diagnostics.Trace.WriteLine(exSetup.ToString())
            End Try
            main()
            Try
                SwMacroCleanup()
            Catch exCleanup As Exception
                System.Diagnostics.Trace.WriteLine(exCleanup.ToString())
            End Try
        End If

    End Sub

The SwMacroSetup() and SwMacroCleanup() are throwing the exceptions. The exceptions look like this:

A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll
System.Runtime.InteropServices.COMException (0x80010105): The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))
   at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)
   at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
   at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args)
   at SolidWorks.OuterDispProxy.SwMacroSetup()
   at Macro1.vbproj.SolidWorksMacro.SolidWorksMacro_Startup(Object sender, EventArgs e) in C:\\Program Files\\SolidWorks Corp\\SolidWorks\\Macros\\Test macro\\Macro1\\SwMacro\\SolidWorksMacroStartup.vb:line 13

and:

A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll
System.Runtime.InteropServices.COMException (0x80010105): The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))
   at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)
   at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
   at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args)
   at SolidWorks.OuterDispProxy.SwMacroCleanup()
   at Macro1.vbproj.SolidWorksMacro.SolidWorksMacro_Startup(Object sender, EventArgs e) in C:\\Program Files\\SolidWorks Corp\\SolidWorks\\Macros\\Test macro\\Macro1\\SwMacro\\SolidWorksMacroStartup.vb:line 19

I'm a bit at a loss on this one...

SolidworksApi macros