API code crashes

Discussion in 'SolidWorks' started by dan9298, Dec 27, 2004.

  1. dan9298

    dan9298 Guest

    I'm using SW2004 SP4.1 & VB.NET 7.1.3088.
    I have written a program that opens several SW drawings and reports
    some information to an excel spreadsheet. Sometimes the code functions
    correctly, sometimes it crashes. The crashes occur in different parts
    of the code (always on a SolidWorks function call).

    Does anyone have any suggestions for things that might be causing the
    crashes? Are there any best-practices that I might be missing?

    Thanks.
     
    dan9298, Dec 27, 2004
    #1
  2. Can you post some of your code and where it crashes?

    I crash SW regularly while using both VB and VB.NET, but it is usually b/c I
    am asking it to do something it does not like to do. I have found them both
    to be very stable in production.

    Evan
     
    Evan T. Basalik, Dec 27, 2004
    #2
  3. dan9298

    Dan Guest

    Evan, thanks for the reply.
    The code crashes on lines such as these (these are examples, not my
    entire code):

    bStatus = oDrawingModel.ShowConfiguration2(sConfigName)
    oDrawingView = oSwDrawing.GetFirstView()
    oSolidWorksApplication.CloseDoc(sConfigName & ".slddrw")

    The error I usually get is:
    An unhandled exception of type
    'System.Runtime.InteropServices.COMException' occurred in
    microsoft.visualbasic.dll
    Additional information: The server threw an exception.

    Using the same test scenarios, it sometimes works, and sometimes
    crashes.
    Any ideas?
     
    Dan, Dec 27, 2004
    #3
  4. Try wrapping your code in a Try, Catch, Finally block:

    Try
    bStatus = oDrawingModel.ShowConfiguration2(sConfigName)
    oDrawingView = oSwDrawing.GetFirstView()
    oSolidWorksApplication.CloseDoc(sConfigName & ".slddrw")
    Catch excCom As COMException
    ' TODO: Handle COM exceptions.
    Catch exc As Exception
    ' TODO: Handle errors.
    Finally
    ' TODO: Clean-up code goes here.
    End Try

    That should stop your application crashing immediately. Then put a break
    point on the Catch for COMException and inspect the values of
    COMException.Message and COMException.HResult. They should give you some
    idea about the type of COM error that you are getting back from SolidWorks.

    MSDN Documentation on COMException is here:

    http://msdn.microsoft.com/library/d...ServicesCOMExceptionClassTopic.asp?frame=true
     
    Paul Delhanty, Dec 28, 2004
    #4
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.