Browse Source

Fix #162 Opening a file that's not a valid assembly displays exception stack trace

pull/252/head
Daniel Grunwald 15 years ago
parent
commit
65f5427ae6
  1. 4
      ILSpy/LoadedAssembly.cs
  2. 12
      ILSpy/TreeNodes/AssemblyTreeNode.cs

4
ILSpy/LoadedAssembly.cs

@ -211,6 +211,10 @@ namespace ICSharpCode.ILSpy @@ -211,6 +211,10 @@ namespace ICSharpCode.ILSpy
return this.assemblyTask.ContinueWith(onAssemblyLoaded, taskScheduler);
}
/// <summary>
/// Wait until the assembly is loaded.
/// Throws an AggregateException when loading the assembly fails.
/// </summary>
public void WaitUntilLoaded()
{
assemblyTask.Wait();

12
ILSpy/TreeNodes/AssemblyTreeNode.cs

@ -195,7 +195,17 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -195,7 +195,17 @@ namespace ICSharpCode.ILSpy.TreeNodes
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
{
assembly.WaitUntilLoaded(); // necessary so that load errors are passed on to the caller
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;
}
}
language.DecompileAssembly(assembly, output, options);
}

Loading…
Cancel
Save