Browse Source

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

pull/1012/head
Siegfried Pammer 8 years ago
parent
commit
ee8841e5bb
  1. 24
      ILSpy/TreeNodes/AssemblyTreeNode.cs

24
ILSpy/TreeNodes/AssemblyTreeNode.cs

@ -251,15 +251,29 @@ namespace ICSharpCode.ILSpy.TreeNodes
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options) 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 { try {
assembly.WaitUntilLoaded(); // necessary so that load errors are passed on to the caller assembly.WaitUntilLoaded(); // necessary so that load errors are passed on to the caller
} catch (AggregateException ex) { } catch (AggregateException ex) {
language.WriteCommentLine(output, assembly.FileName); language.WriteCommentLine(output, assembly.FileName);
if (ex.InnerException is BadImageFormatException) { switch (ex.InnerException) {
language.WriteCommentLine(output, "This file does not contain a managed assembly."); case BadImageFormatException badImage:
return; HandleException(badImage, "This file does not contain a managed assembly.");
} else { return;
throw; case FileNotFoundException fileNotFound:
HandleException(fileNotFound, "The file was not found.");
return;
default:
throw;
} }
} }
language.DecompileAssembly(assembly, output, options); language.DecompileAssembly(assembly, output, options);

Loading…
Cancel
Save