none
Application.Exit Throwing "FIleNotFoundException was unhandled"

    Question

  • I have an app with a Close button.  The click handler consists of only one statement:  Application.Exit.  But that statement gets an exception: "FileNotFoundException was unhandled".  What file?  Why would Application.Exit be looking for any file?

    If I trap the exception here's the Exception.ToString (below)

    Can anyone help me understand what is going on?

    Thanks,  Bob


    Monday, July 22, 2013 1:01 AM

Answers

All replies

  • Hi,

     Are you using the Form_Closing or Form_Closed events to delete or modify a file. If not then maybe you should try using (Me.Close) if the close button is on your main form.

    Monday, July 22, 2013 1:20 AM
  • post the source code so someone can check it for errors

    Monday, July 22, 2013 3:21 AM
  • Hi,

     Are you using the Form_Closing or Form_Closed events to delete or modify a file. If not then maybe you should try using (Me.Close) if the close button is on your main form.

    This is code I wrote a long time ago for a customer.  My recollection is that FormClosing/Closed did not work.  It is certainly my practice to choose the most gentle API possible which will get the job done. 

    The customer has never complained about this.  But it's very possible he doesn't experience the problem.  I can't replicate his environment because there is a hardware dependency.

    Thanks IronRazerz. 

    Bob

    Tuesday, July 23, 2013 6:34 PM
  • post the source code so someone can check it for errors

    Thanks Devon.  I'd like to but it's proprietary.  The sub consists of just the one statement:

    Application.Exit

    Bob

    Tuesday, July 23, 2013 6:36 PM
  • Hello,

    If this is the first time and the app has been in use for sometime then something must have changed in their environment such as permissions or group policies, OS update or new OS.

    If of course they have been tolerating this for a while then it would not be from their environment.

    If you are not deleting any files there may be code that creates temp files and is cleaning up when the exception is thrown which goes back to environment issues.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Tuesday, July 23, 2013 6:51 PM
  • Hi,

     Are you using the Form_Closing or Form_Closed events to delete or modify a file. If not then maybe you should try using (Me.Close) if the close button is on your main form.

    This is code I wrote a long time ago for a customer.  My recollection is that FormClosing/Closed did not work.  It is certainly my practice to choose the most gentle API possible which will get the job done. 

    The customer has never complained about this.  But it's very possible he doesn't experience the problem.  I can't replicate his environment because there is a hardware dependency.

    Thanks IronRazerz. 

    Bob

    Hi,

     I really don`t understand your answer. Every VB form project has a Form_Closing and Form_Closed event that is triggered when your program is closing or closed. It is just a matter of are you using one of them to Delete or Modify a file somehow when your program is closing or closed. If so then maybe the file it is deleting or modifying can not be found. Perhaps you have added a sub or function in your program that does something with a file when the user presses the close button and the file can`t be found. I see that in your error message it says something about line 823. Is that the (Application.Exit) line?

    Tuesday, July 23, 2013 10:16 PM
  • If I read the tiny image you posted I see it says "The specified module could not be found"

    possibly a dll is being called as part of the app cleanup and it is missing or one of its dependencies is missing. Usually the exception window shows what file is causing the problem.

    maybe one of these will help

    http://social.msdn.microsoft.com/Forums/vstudio/en-US/14dc569b-b761-4021-b3a7-559138daaf71/the-specified-module-could-not-be-found

    http://www.codeproject.com/Articles/337593/DLL-Dependency-Viewer-or-How-To-Fix-Exception-Unab

    Wednesday, July 24, 2013 2:03 AM
  • Thank you IronRazerz for your continued interest.  I don't understand what I wrote yesterday either.  I was probably thinking of the Form.Close method rather than the Closing/Closed events. 

    Yes, line 823 is the line of the Application.Exit statement.

    At this point since the customer is completely happy with the app my interest is mostly academic.  Other than reading the references provided by Devon_Nullman I plan no further pursuit of this. 

    Thanks again for your interest.

    Bob

    Wednesday, July 24, 2013 5:28 PM
  • Thank you Devon_Nullman for replying and for the references.  I'll be reading them but otherwise, since the customer is deliriously happy with the app, I plan no further pursuit of this.

    Thanks again,  Bob

    Wednesday, July 24, 2013 5:31 PM