BobSki
BobSki

Reputation: 1552

Unhandled win32 exception occured in the application

I have an application in vb.net that I'm testing out in Windows 10 and I seem to be getting an error (Images below). This app works flawlessly in Windows 7, and it actually works without any issues in Windows 10, the problem is, when I exit the application is when I get the error.

The way it's structured, is if I run it from IDE, i first see a Login Windows where user logs in and then goes to MENU. If it's run in our environment, user does not have to log in, so the log in form never appears, it goes directly to MENU.

Everything works great, until I go to EXIT Application, where it gets all messy, this is the code from EXIT button...

    Dim Answer as Integer
    Answer = MsgBox("Are you sure you wish to Close the application ?", MsgBoxStyle.YesNo)
    If answer = vbYes Then
        End
    End If

These are the errors I get:

enter image description here First I get this error, clicking on CLOSE PROGRAM closes it completely, if I click debug I get the below windows....

enter image description here

With the 2nd error it shows that I actually have VS2010 and VS2012, and it lets me debug. The issue is, the source code is in TFS, and it just so happens that I can't access the TFS from my windows 10 machine, (only from Win 7). So I can't debug it. But is there a reason why this is happening only in windows 10?

I even went as far as doing Me.Close() before END to make srue that the form is closed. And again, it works fine in Win 7, but win 10 it gives me the same problems.

Upvotes: 0

Views: 946

Answers (1)

soohoonigan
soohoonigan

Reputation: 2360

Using "End" to close a program can be problematic; the comments and answer to this SO question explain why that is. As for the second issue that popped up once using Application.Exit(), that is a simple case of your program referencing multiple assemblies that have function calls with the same name. In this case, both the explicitly imported Microsoft.Office.Interop.Excel and implicitly imported System.Windows.Forms have "Application.Exit()" members. Since you have explicitly imported Excel, the compiler goes with that one when it's forced to decide which Exit() to use, which throws an error because of the context it's being used and doesn't actually close the program. To rectify that, all you have to do is explicitly tell the compiler which Exit() you want to use by replacing

Application.Exit()

with

System.Windows.Forms.Application.Exit()

Upvotes: 1

Related Questions