No error message from add-in

No error message from add-in

AJK2010
Enthusiast Enthusiast
1,898 Views
18 Replies
Message 1 of 19

No error message from add-in

AJK2010
Enthusiast
Enthusiast

Hey,

My add-in worked great in inventor 2018.

After the upgrade to inventor 2020 my add-in freezes inventor when an error is happening.

I use Try in my add-in to intercept the error and to show a messagebox to the user.

But the messagebox is not shown and inventor freezes.

If there is no try in my code and there is an error inventor is not showing an error message either and freezes.

In the attachments there is a screenshot of te error message I am missing.

I don't know if an update from windows 10 or .net or inventor is causing the missing error message.

 

There is no other way to resume your work then kill inventor with the taskmanager.

 

Are there people with the same problem?

What can i do to solve this problem?

 

0 Likes
1,899 Views
18 Replies
Replies (18)
Message 2 of 19

HideoYamada
Advisor
Advisor

Hi,

 

I am creating and using the add-ins in following environment :

* Windows 10 1909

* Inventor 2020.2

 

I fell that Inventor older then 2020 are ignore exceptions that are thrown by add-ins, and Inventor 2020 shows an error dialog.

This phenomenon is not compared exactly and may be wrong (lie).

But some of my add-ins showed the error dialog when I migrate to Inventor 2020, and the dialog had caused by not caught exceptions in my add-ins.

 

=====

Freeradical

 Hideo Yamada

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes
Message 3 of 19

Dev_rim
Advocate
Advocate

Hello,

Which AddIn template you have?

Did you convert the AddInServer.vb for 2020. And which version of Framework are you using?

If my answer is solved your problem, please mark it as Solution

Freundliche Grüße / Kind Regards
0 Likes
Message 4 of 19

CattabianiI
Collaborator
Collaborator

The exception is thrown in TitleBlockCopy method where you said that you have the Try Catch statement:
- make sure to catch the generic Exception (at least for now),
- make sure to not throw Exception in Catch block! Use a simple MsgBox for now,
- simplify your method and raise an exception yourself:

Try
  Throw New Exception("I should have checked if object was null!")
Catch ex As Exception 
  MsgBox(ex.ToString(), MsgBoxStyle.Critical, "MY EX MESSAGE")
End Try 


Try to make the same operation TitleBlockCopy method does thru UI instead.

You have Inventor 2020.2 and nothing I said before was useful? Try to uninstall last update and reproduce the issue.

 

0 Likes
Message 5 of 19

HermJan.Otterman
Advisor
Advisor

could the messagebox be off the screen or below Inventor?

did you try to run the code from visual studio?

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes
Message 6 of 19

AJK2010
Enthusiast
Enthusiast

There is no screen, Inventor just hangs with a wait cursor and my form stays in front.

The problem is that inventor gives sometimes an error on an operation, and then i restart the inventor and the operation goes good for a 100 times.

So i can't really debug this.

An example:

            Try
                If oview.Height > oview.Width Then
                    oview.RotateByAngle(1.57079633, True)
                End If
            Catch ex As Exception
                If MsgBox("error", MsgBoxStyle.YesNo, "error") = MsgBoxResult.No Then
                    Exit Sub
                End If
            End Try

Sometimes placing a note on a drawing gives an error, Restart inventor and placing the note on the same drawing works great.

An other example is when i try to know if a sheetmetal has a bend.

Try
                If oSheetMetalCompDef.Bends.Count > 0 Then
                    oBended = True
                End If
                'Sometimes this gives an error and than I check the flatpattern
            Catch e As Exception
                If oSheetMetalCompDef.HasFlatPattern = True Then
                    Try
                        If oSheetMetalCompDef.FlatPattern.FlatBendResults.Count > 0 Then
                           oBended = True
                        End If
                    Catch ex As Exception
                        msgbox ("can't check if sheetmetal is bend!")                        
                    End Try
                Else
msgbox ("can't check if sheetmetal is bend!")  
End If
            End Try

I also have a code to check if there is a thread in the part. This also freezes inventor sometimes.

This code worked great before we update to inventor 2020

Now inventor freezes and we have to restart.

After the restart the code can run great on the same part or drawing,

but can go wrong on an other.

 

So i have inserted the try so inventor sometimes cannot do something that he can do after a restart, with the same project and files. But when the try goes to the catch, than the user can close the form and save his work without Inventor hanging. Now he must close inventor whit task-manager and reopen inventor and all the files he is working with and the changes he has made and not saved or gone.

 

This is very frustrating.

0 Likes
Message 7 of 19

AJK2010
Enthusiast
Enthusiast

I used my Addin for inventor 2015 to convert it to inventor 2018, and then i converted it to 2020.

I just deleted the reference to the older dll and added the dll from the new inventor.

then I looked for errors in my code and solved them and then I recompiled the Addin.

 

Is there something special in de StandardAddInServer code that i have to look for?

 

Framework 4.5

 

I made a new Addin from start with the template for inventor2020, only with the program that causes inventor to hang.

I have installed it with one user for testing.

I hope this works.

 

0 Likes
Message 8 of 19

Dev_rim
Advocate
Advocate

I use "SimpleAddIn" project always when i need a template project. Project Folder in :

C:\Users\Public\Documents\Autodesk\Inventor 2020\SDK\DeveloperTools\Samples\VB.NET\AddIns

If you cant reach to folder try to install developertools.msi in:

C:\Users\Public\Documents\Autodesk\Inventor 2020\SDK

Simple Add-In project works with simple class logic. Its to easy for editing. You can try this.

 

It might be a logic error if your inventor freezes, so maybe you change the addIn Template.

 

And one more thing to add. Sometimes Framework 4.5 and templates dont match each other. This might be your problem. 

If my answer is solved your problem, please mark it as Solution

Freundliche Grüße / Kind Regards
0 Likes
Message 9 of 19

AJK2010
Enthusiast
Enthusiast

Which framework do i have to use than?

0 Likes
Message 10 of 19

AJK2010
Enthusiast
Enthusiast

When i do a 

Throw New Exception("I should have checked if object was null!")

in my code, the try is working fine and goes to the catch.

I see the msg and inventor doesn't hang.

 

I think inventor hangs when doing the command and doesn't pass the exception back to my add-in.

 

0 Likes
Message 11 of 19

CattabianiI
Collaborator
Collaborator

Looking at your code make me think about what I said a few days ago:
- make sure to not throw Exception in Catch block! Use a simple MsgBox for now,

If oSheetMetalCompDef is malformed or simply null you will raise an exception inside the catch block and probably  you are inside the catch block for the very same reason; it would be better to check null before being in the catch block, by the way you could try to try catch the entire catch block:

            If oSheetMetalCompDef.Bends.Count > 0 Then
                oBended = True
            End If
            'Sometimes this gives an error and than I check the flatpattern
        Catch e As Exception
            Try
                If oSheetMetalCompDef.HasFlatPattern = True Then
                    If oSheetMetalCompDef.FlatPattern.FlatBendResults.Count > 0 Then
                        oBended = True
                    End If
                Else
                    MsgBox("can't check if sheetmetal is bend!")
                End If
            Catch ex As Exception
                MsgBox("can't check if sheetmetal is bend!")
            End Try
        End Try


You might even try to reproduce the Inventor getting stuck systematically, change your method in something like this:

Try
  Throw New Exception("I should have checked if object was null!")
Catch ex As Exception 
Throw New Exception("The object was null, and I'm calling a method on it in a catch block: this is BAD!") ' ... I could have try catched the second exception at least... End Try


What 's changed from Inventor 2018? Many things, maybe the Inventor exception handling during commands or even the .NET framework exception handling, however what I showed you is a safer way to manage exception.

0 Likes
Message 12 of 19

AJK2010
Enthusiast
Enthusiast

Changed my code, with no result.

I think it is strange that inventor doesn't handle an error.

When i make a small windows program and i throw an exception without the try catch, I get an error dialogbox.

When i throw an exception in my add-in in inventor, nothing happens.

In the past i always got the same error dialog as the windows app when an error happens in my add-in.

Inventor just blocks this or does not handle the error and showing me the error dialog.

There is no warning that there is going something wrong in the add-in.

When i throw an exception in a try than the code is handled and goes to catch. So this works ok.

I have the feeling that sometimes inventor freezes on the actions that i do with my add-in and can't give the exception back to my add-in. So my add-in can't handle the error and stop the add-in and keep inventor responsive.

 

We did the upgrade from inventor 2018 to 2020 because 2020 is handling large assembly much better than 2018.

But now this is a big problem.

Can someone please make a small test add-in, trow an exception and confirm that he also doesn't get the error dialog?

See the attached screenshot, this is the dialog i get with the windows program, and that i am missing when the same exception is thrown in inventor.

0 Likes
Message 13 of 19

Dev_rim
Advocate
Advocate

I'm using 3.5

If my answer is solved your problem, please mark it as Solution

Freundliche Grüße / Kind Regards
0 Likes
Message 14 of 19

CattabianiI
Collaborator
Collaborator

> Can someone please make a small test add-in, trow an exception and confirm that he also doesn't get the error dialog?

I do not confirm your behaviour! I got the error dialog.

Could you please make a simple test add-in, throw an exception which is not shown and attach the addin project here? Or maybe just the AddInServer.(vb | cs) file, if you do all the work in there.

0 Likes
Message 15 of 19

AJK2010
Enthusiast
Enthusiast

Hey I made a small add-in with only a form and two buttons.

Behind the buttons one exception without try and the second button one exception with the try.

This add-in works on my system too and gives me the error dialog.

There must be something in my other add-in that prevents this.

Thanks for testing.

 

0 Likes
Message 16 of 19

CattabianiI
Collaborator
Collaborator

> There must be something in my other add-in that prevents this.
As suspected 🙂

If you can really simplify your addin and still reproduce the issue, share it here so we\I could take a look. 

In any case please be sure to not raise an exception inside catch block!
I hope you do not have anymore lines like these:

  Catch e As Exception
      If oSheetMetalCompDef.HasFlatPattern = True Then

 

0 Likes
Message 17 of 19

CattabianiI
Collaborator
Collaborator

EDIT:
> In any case please be sure to not raise an exception inside catch block!
Why?
Because if there isn't an outer catch no one will ever catch and prompt you that exception anymore!
And if you have object to close or selection in progress no one will ever close or stop them and maybe Inventor freezes.

 

Or it would be great if you could just reproduce the issue in an iLogic rule.

0 Likes
Message 18 of 19

AJK2010
Enthusiast
Enthusiast

Hey,

I have succeeded in reproducing the problem.

I made a small add-in with a form with two buttons.

When I throw an exception from a sub runned by a button on the form than the exception is handled as expected.

When I throw an exception in the code before I show the form, there is no error and inventor does nothing.

 

Module Module1
    Dim NewFrmTest As FrmTest
    Dim NewFrmTest2 As FrmTest
    Public Sub initFormtest() 'run with button1
        NewFrmTest = New FrmTest
        NewFrmTest.ShowDialog()
    End Sub

    Public Sub initFormtest2() 'run with button2

        'run some code before showing the dialog
        'and some Exception occurred
        Throw New Exception("Test Error Handling1") 'Inventor just stops the code, and there is nothing happening
        NewFrmTest2 = New FrmTest
        NewFrmTest2.ShowDialog()
    End Sub

    Public Sub Test1() 'run with button1 on Frmtest
        Throw New Exception("Test Error Handling2") 'Exception is handled like expected with an error window
    End Sub

    Public Sub Test2() 'run with button2 on Frmtest
        Try
            Throw New Exception("Test Error Handling With Try") 'Exception is handled by the try
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

End Module

In the attachment you find my vb project.

 

This is one problem.

 

The other problem is that with my code I save the inventor dwg as DXF.

Sometimes inventor just hangs while saving the DXF, there is no error.

We just have to close inventor with task-manager.

When we restart inventor saving the dxf from the same file just works.

 

0 Likes
Message 19 of 19

CattabianiI
Collaborator
Collaborator

Short answer: add always try catch in OnExecute event handler, and in any event handler as a general rule; and google how bad is raising an exception in .NET event handler.

Some other things:

When i make a small windows program and i throw an exception without the try catch, I get an error dialogbox.

That's very not true, if no one catch your exception the program crash (create a one minute console application). What you're talking about is raising an exception inside a form and is what you do in Test1 method, the exception is shown because in NativeWindow.cs there is a try catch. 

I don't know if and what has changed since Inventor 2018, in any case this wouldn't be a bug: it's up to you to manage the exception in event handler.

Please add try catch (AND do not raise an exception in catch block 😂) and then ask here on the forum for unknown or unwanted exception/behavior.

About the other problem: first of all try to export thru UI, then check on google because is a quite popular issue and eventually post here or on the main Inventor forum your particular problem.

Thanks!

0 Likes