Search code examples
c#windows-7folderbrowserdialog

FolderBrowserDialog crashes the application


Whenever I call folderbrowserdialog.showDialog() my application crashes. I'm using the code that worked before for me, so it CAN NOT be the code.

try
{
    FolderBrowserDialog fbd = new FolderBrowserDialog();
    fbd.RootFolder = Environment.SpecialFolder.Desktop;
    if (fbd.ShowDialog() == DialogResult.OK)
    {
        //  this.Minecraft.Text = fbd.SelectedPath;
    }
}
catch
{
}

It does not throw any error, no exception, there just pops up the little loading circle, then the app is gone, I noticed it with a different .NET app before too!

btw: will reinstalling .net 4 work?


Solution

  • Try adding this to your application (at the start of the Main() method, preferably). See if the exceptions.txt file has any exceptions logged into it when you reach your freezing point.

            AppDomain.CurrentDomain.FirstChanceException += (sender, e) =>
            {
                if ((e == null) || (e.Exception == null))
                {
                    return;
                }
    
                using (var sw = File.AppendText(@".\exceptions.txt")) 
                {
                    sw.WriteLine(e.ExceptionObject);
                }                
            };
    
            AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
            {
                if ((e == null) || (e.ExceptionObject == null))
                {
                    return;
                }
    
                using (var sw = File.AppendText(@".\exceptions.txt")) 
                {
                    sw.WriteLine(e.ExceptionObject);
                }                
            };