Asked by:
Exception thrown: 'System.ArgumentException' in mscorlib.dll

Question
-
Hey
I would like to understand & manage this error better. I am working with Autodesk Inventor and with some of the API functions, there is a need to cause an error in order process. for example; adding properties or activating a project.
Properties. its recommended to try are write to it first if it exists and if it doesnt exist, catch the error and add the property then write to it.
Project. again, try and activate it first and if it doesnt exist, create it then activate it.
Private Sub SetActiveProject() 'check for open files and bail if any exist Try 'try to activate the project based on the root folder & CompName Dim ProjPath As String = ProjectsRootFolder & "\" & CompName & "\" & CompName & ".ipj" oProject = oDesignProjectMgr.DesignProjects.ItemByName(ProjPath) oProject.Activate() UpdateProcessList("Activating existing Project - " & oProject.Name, True, True) Catch ex As Exception 'create the project if it doesnt exist oProject = oDesignProjectMgr.DesignProjects.Add(MultiUserModeEnum.kSingleUserMode, CompName, ProjectsRootFolder & "\" & CompName) oProject.Activate() End Try End Sub
There are also other API functions that require this behaviour. In my immediate window, i get this error
Exception thrown: 'System.ArgumentException' in mscorlib.dll
i would prefer to be able to handle this properly so that instead of this error, i get a meaningful message related to the specific error caught at the time. For example: iProperty x doesnt exist, creating new which is then something i can add to a log. At the same time, i would like to remove the Exception thrown error.
I can write a log message in the Catch but im not sure thats enough to handle it properly. Can the Exception thrown message be suppressed and replaced with a custom message? I am add / updating up to 5000 properties in a model set so 1000's of Exception thrown errors doesnt really explain anything to me..
Thanks
Im a self taught VB.Net guy who writes code for Autodesk Inventor. I may not know the terminology but i try so please be patient. Im not a kid so please dont treat me like one :)
- Moved by Xingyu ZhaoMicrosoft contingent staff Thursday, April 30, 2020 8:03 AM
Tuesday, April 28, 2020 6:21 PM
All replies
-
Hi
I know nothing about Autodesk Inventor, but am wondering if you can deal with these issues in a different way. For example, using an If ... Then block, test for the existance of the item and if doesn't exist, create it and call the Private Sub SetActiveProject() again and presumably, since you have now created it, the Exception won't happen. However, be careful to not create an infinitr loop doing this.
Also, are you aware that you can deal with specific Exceptions separately, such as:
Try ' ............ Catch ex As ArgumentException MessageBox.Show("Argument Exception ....") Catch ex As Exception MessageBox.Show("General Exception ....") End Try
and so, maybe write a more appropriate Log message.
Regards Les, Livingston, Scotland
Tuesday, April 28, 2020 6:52 PM -
Hi
Thanks for the reply. I did change my project method to your suggestion like this
Try 'try to activate the project based on the root folder & CompName name Dim ProjPath As String = ProjectsRootFolder & "\" & CompName & "\" & CompName & ".ipj" If Not IO.File.Exists(ProjPath) Then oProject = oDesignProjectMgr.DesignProjects.Add(MultiUserModeEnum.kSingleUserMode, CompName, ProjectsRootFolder & "\" & CompName) oProject.Activate() Else oProject = oDesignProjectMgr.DesignProjects.ItemByName(ProjPath) oProject.Activate() End If Catch ex As ArgumentException End Try
This does remove the Exception error. I cant do the same on the properties unfortunately as they are not an object and the API doesnt provide a method of checking if it exists. The API documentation provides the method of forcing the error.
The error message in the immediate window is that much of a problem, the error after all is supposed to be there but personally, it doubles up the immediate window space and makes it a little harder to read through.. I can live with it of course, would be nice if i could suppress it all the same :)
Thanks again
Im a self taught VB.Net guy who writes code for Autodesk Inventor. I may not know the terminology but i try so please be patient. Im not a kid so please dont treat me like one :)
Tuesday, April 28, 2020 8:28 PM -
Hi NachoShaw,
Thanks for your feedback.
I note that Autodesk Inventor is a third-party product for which we don't provide help, so you can consider posting your question in related forums for more help.
Thank you and have a nice day.
Best Regards,
Xingyu Zhao
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.Thursday, April 30, 2020 8:03 AM