AnsweredAssumed Answered

Unable to cast COM object of type 'System.__ComObject' to interface type 'SolidWorks.Interop.sldworks.ModelDoc2'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{B90793FB-EF3D-4B80-A5C4-99959CDB6CEB}

Question asked by Hans Vindevoghel on Jun 21, 2016
Latest reply on Jun 21, 2016 by Artem Taturevych

Hello,

 

I wrote a program for PDM workgroup that when a designer checks in a document it create the needs dxf, step and pdf for part, assembly and drawing and puts them into a zip file so we can send 1 zip to someone and he will have all the files he needs for buying, milling, ....

 

This program has been running successfully on my Windows 2008 R2 server with Solidworks 2011. We recently updated to Windows Server 2012 R2 with Solidworks 2016 SP3.

 

I have updated my libraries on my developer machine and it runs successfully but it gives me this error on the new server "Unable to cast COM object of type 'System.__ComObject' to interface type 'SolidWorks.Interop.sldworks.ModelDoc2'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{B90793FB-EF3D-4B80-A5C4-99959CDB6CEB}' failed due to the following error: Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY))."

 

Imports System.IO

imports Sldworks

 

Module Main

    Public swApp As Sldworks.Sldworks

 

    Sub Main()

        Try

            swApp = CreateObject("SldWorks.Application")

        Catch ex As Exception

            File.AppendAllText("c:\temp\Error.log", "   Critical Error processed with reason " & ex.Message & vbCrLf)

        End Try

    End Sub

End Module

 

Solidworks start in the back group but I get the error in my log file.

I can fix this by using "as Object" instead of "Sldworks.Sldworks" but the problem continues in my opening and saving of the step files.(code below)

 

Imports System.IO

Imports SwConst

Imports Sldworks

 

Module Main

    Sub Main()

    

     Dim swPart As SldWorks.PartDoc

     Dim swModel As SldWorks.ModelDoc2

     Dim swModelDocExt As SldWorks.ModelDocExtension

     Dim tmpPath as String

     Dim DocumentName as String

     Dim Output_Filename as String

    

     Try

          swPart = swApp.OpenDoc6(tmpPath & "\" & DocumentName, swDocumentTypes_e.swDocPART, swOpenDocOptions_e.swOpenDocOptions_Silent, "", Errors, Warnings)

          swModel = swPart

 

          If Not swModel Is Nothing Then

               swApp.SetUserPreferenceIntegerValue(swUserPreferenceIntegerValue_e.swStepAP, 214)

               swModelDocExt = swModel.Extension

               swModelDocExt.SaveAs(tmpPath & "\" & Output_Filename & ".step", swSaveAsVersion_e.swSaveAsCurrentVersion, swSaveAsOptions_e.swSaveAsOptions_SaveReferenced, Nothing, Errors, Warnings)

          End If

     Catch ex As Exception

          File.AppendAllText("c:\temp\Error.log", "   Critical Error processed with reason " & ex.Message & vbCrLf)

     End Try

    End Sub

End Module

 

Can someone help me?

Outcomes