dcsimg
Results 1 to 2 of 2
  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2013
    Posts
    206

    Unhandled Exception on Console App

    Hello:

    I am using VS 2017, and have set the Framework to 4.51. I have a console application (exe file) that runs great on my system with VS installed, but get this error on other systems. I have tried to turn off Just In Time debugging (this was the initial error which seems to have gone away), but am still getting the error shown in the attachment.

    The only references are for SolidWorks, which is installed on all systems we are trying to run this on. To my knowledge, I do not need to create an installation deployment on console apps, but perhaps this is wrong.

    Name:  Screen Shot 12-29-17 at 04.16 PM.jpg
Views: 179
Size:  22.6 KB

    Code:

    Code:
    Option Strict Off
    
    Imports System
    Imports System.Diagnostics
    Imports System.Collections
    Imports System.Configuration
    Imports System.Data
    Imports System.Data.SqlClient
    Imports System.Drawing
    Imports System.IO
    Imports System.Math
    Imports System.Text
    
    Imports SolidWorks.Interop.sldworks
    Imports SolidWorks.Interop.swcommands
    Imports SolidWorks.Interop.swconst
    Module Module1
        Public _Cacheddirectory As String = "C:\"
        Public SWAPP As New SldWorks
        Public SWMODEL As ModelDoc2 = SWAPP.ActiveDoc
    
        Sub Main()
            ' Get all Weldment Profiles from model
            Dim swPart As ModelDoc2 = SWMODEL
            Dim swFeat As Feature = swPart.FirstFeature
            Dim swFeatData As StructuralMemberFeatureData
            Dim sProfilePath As String = "C:\Sackett-Waconia\Master Documents\SOLIDWORKS TEMPLATES\weldment profiles\_WMI Profiles_"
            Dim cfgName As String
    
            Dim bAutoUpdate As Boolean
            Dim swCutList As BodyFolder
    
            Dim al_featnames As New ArrayList
            Dim al_featdescs As New ArrayList
    
            Do While Not swFeat Is Nothing
                If swFeat.GetTypeName = "SolidBodyFolder" Then
                    swCutList = swFeat.GetSpecificFeature2
    
                    ' Get automatic update setting
                    bAutoUpdate = swCutList.GetAutomaticUpdate
    
                    ' Disable automatic update for cutlist
                    swCutList.SetAutomaticUpdate(False)
    
                End If
    
                If swFeat.GetTypeName = "WeldMemberFeat" Then
                    ' Read Info
                    al_featnames.Add(swFeat.Name)
                    al_featdescs.Add(swFeat.Description)
    
                    ' Update Profile
                    Dim sFullProfilePath As String = GetProfile(swFeat, sProfilePath)
                    Debug.WriteLine(sFullProfilePath)
                    swFeatData = swFeat.GetDefinition
                    cfgName = swFeatData.ConfigurationName
                    swFeatData.AccessSelections(swPart, Nothing)
                    swFeatData.WeldmentProfilePath = sFullProfilePath
    
                    ' Write Info back
                    swFeatData.ConfigurationName = cfgName
    
                    ' If feature is not updated
                    If Not swFeat.ModifyDefinition(swFeatData, swPart, Nothing) Then
                        Debug.WriteLine("Unable to update feature " & swFeat.Name)
    
                    End If
    
                End If
    
                swFeat = swFeat.GetNextFeature
    
            Loop
    
            swCutList.UpdateCutList()
            swCutList.SetAutomaticUpdate(bAutoUpdate)
    
            swFeat = swPart.FirstFeature
    
            Dim c As Integer = 0
            Do While Not swFeat Is Nothing
                If swFeat.GetTypeName = "WeldMemberFeat" Then
                    ' Write Feature Names and Descriptions back
                    swFeat.Name = al_featnames(c)
                    swFeat.Description = al_featdescs(c)
                    c = c + 1
    
                End If
    
                swFeat = swFeat.GetNextFeature
    
            Loop
    
            Console.WriteLine("Done.")
            Console.ReadLine()
    
        End Sub
    
        Private Function GetProfile(feat As Feature, profilePath As String) As String
            Dim Files As String() = Directory.GetFiles(profilePath)
            Dim fileName As String
            Dim weldmentProfile As String
            For Each fileName In Files
                Dim fileName2 = Path.GetFileNameWithoutExtension(fileName)
                If Microsoft.VisualBasic.InStr(feat.Name.ToLower, fileName2.ToLower) <> 0 Then
                    weldmentProfile = fileName
                    Exit For
    
                End If
    
            Next
    
            Return weldmentProfile
    
        End Function
    
    
    
    End Module
    Thanks in advance for information!

  2. #2
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    5,622

    Re: Unhandled Exception on Console App

    I think the COM object is throwing an error at this line:-
    Code:
    swFeatData.WeldmentProfilePath = sFullProfilePath
    Perhaps the COM object tries to do something with the file when you set that property. Under that assumption, you should check to see if the file exists or if it is locked for some reason.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena


    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. -jmcilhinney

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width


×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.