Browse Source

Fix #1532: Display metadata token in DecompilerException error message

pull/1612/head
Daniel Grunwald 6 years ago
parent
commit
abcef43dba
  1. 10
      ICSharpCode.Decompiler/DecompilerException.cs

10
ICSharpCode.Decompiler/DecompilerException.cs

@ -21,6 +21,7 @@ using System.Diagnostics; @@ -21,6 +21,7 @@ using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Reflection.Metadata;
using System.Reflection.Metadata.Ecma335;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Security;
@ -44,7 +45,7 @@ namespace ICSharpCode.Decompiler @@ -44,7 +45,7 @@ namespace ICSharpCode.Decompiler
public PEFile File { get; }
public DecompilerException(MetadataModule module, IEntity decompiledEntity, Exception innerException, string message = null)
: base(message ?? "Error decompiling " + decompiledEntity?.FullName, innerException)
: base(message ?? GetDefaultMessage(decompiledEntity), innerException)
{
this.File = module.PEFile;
this.Module = module;
@ -57,6 +58,13 @@ namespace ICSharpCode.Decompiler @@ -57,6 +58,13 @@ namespace ICSharpCode.Decompiler
this.File = file;
}
static string GetDefaultMessage(IEntity entity)
{
if (entity == null)
return "Error decompiling";
return $"Error decompiling @{MetadataTokens.GetToken(entity.MetadataToken):X8} {entity.FullName}";
}
// This constructor is needed for serialization.
protected DecompilerException(SerializationInfo info, StreamingContext context) : base(info, context)
{

Loading…
Cancel
Save