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. 20
      ILSpy/TreeNodes/AssemblyTreeNode.cs

20
ILSpy/TreeNodes/AssemblyTreeNode.cs

@ -251,14 +251,28 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -251,14 +251,28 @@ 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.");
switch (ex.InnerException) {
case BadImageFormatException badImage:
HandleException(badImage, "This file does not contain a managed assembly.");
return;
} else {
case FileNotFoundException fileNotFound:
HandleException(fileNotFound, "The file was not found.");
return;
default:
throw;
}
}

Loading…
Cancel
Save