From ee8841e5bb0e2f3ed0feb7ee8fd4336afb16f3a7 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 14 Dec 2017 11:28:15 +0100 Subject: [PATCH] Fix #561: Clicking on a node with a deleted file causes a stacktrace to be printed instead of a user friendly "File doesn't exist" message --- ILSpy/TreeNodes/AssemblyTreeNode.cs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/ILSpy/TreeNodes/AssemblyTreeNode.cs b/ILSpy/TreeNodes/AssemblyTreeNode.cs index 57631af2a..8e418b6ef 100644 --- a/ILSpy/TreeNodes/AssemblyTreeNode.cs +++ b/ILSpy/TreeNodes/AssemblyTreeNode.cs @@ -251,15 +251,29 @@ namespace ICSharpCode.ILSpy.TreeNodes public override void Decompile(Language language, ITextOutput output, DecompilationOptions options) { + void HandleException(Exception ex, string message) + { + language.WriteCommentLine(output, message); + + output.WriteLine(); + output.MarkFoldStart("Exception details", true); + output.Write(ex.ToString()); + output.MarkFoldEnd(); + } + try { assembly.WaitUntilLoaded(); // necessary so that load errors are passed on to the caller } catch (AggregateException ex) { language.WriteCommentLine(output, assembly.FileName); - if (ex.InnerException is BadImageFormatException) { - language.WriteCommentLine(output, "This file does not contain a managed assembly."); - return; - } else { - throw; + switch (ex.InnerException) { + case BadImageFormatException badImage: + HandleException(badImage, "This file does not contain a managed assembly."); + return; + case FileNotFoundException fileNotFound: + HandleException(fileNotFound, "The file was not found."); + return; + default: + throw; } } language.DecompileAssembly(assembly, output, options);