I'm writing a WPFapplication where at some point i have to deserialize a binary file into a singleton class. Everything is fine, except that if i put a MessageBox.Show() inside the catch clause i incur in the message being triggered. The problem is that i can't go in with the debug, and Console.Writeline() does not output anything, moreover i have also tried to close the application with Application.Current.Shutdown() but the application keeps running.
My guess is that there is some kind of bug going on, i would like to know what cause the problem.
Here is the code:
public void Deserialize(string filename)
{
BinaryReader br = null;
try
{
br = new BinaryReader(new FileStream(filename, FileMode.Open));
//Do deserialization
}
catch (Exception e)
{
MessageBox.Show(e.ToString(), "An error has occured while loading.", MessageBoxButton.OK, MessageBoxImage.Error); //message is being thrown with FileNotFound exception
Console.WriteLine("An error occured:" + e.ToString());//never prints
Application.Current.Shutdown();//never closes application
}
finally
{
br?.Close();
}
}
The problem seems related to VisualStudio, I am using the enterprise edition 2015. However it does not always occur.