Browse Source

Do not crash on files that contain no managed metadata.

pull/1420/head
Siegfried Pammer 7 years ago
parent
commit
af594e46b9
  1. 31
      ICSharpCode.Decompiler/Metadata/EnumUnderlyingTypeResolveException.cs
  2. 2
      ICSharpCode.Decompiler/Metadata/PEFile.cs
  3. 3
      ILSpy/TreeNodes/AssemblyTreeNode.cs

31
ICSharpCode.Decompiler/Metadata/EnumUnderlyingTypeResolveException.cs

@ -23,22 +23,25 @@ using System.Text;
namespace ICSharpCode.Decompiler.Metadata namespace ICSharpCode.Decompiler.Metadata
{ {
[Serializable]
public class EnumUnderlyingTypeResolveException : Exception public class EnumUnderlyingTypeResolveException : Exception
{ {
public EnumUnderlyingTypeResolveException() public EnumUnderlyingTypeResolveException() { }
{ public EnumUnderlyingTypeResolveException(string message) : base(message) { }
} public EnumUnderlyingTypeResolveException(string message, Exception inner) : base(message, inner) { }
protected EnumUnderlyingTypeResolveException(
public EnumUnderlyingTypeResolveException(string message) : base(message) SerializationInfo info,
{ StreamingContext context) : base(info, context) { }
} }
public EnumUnderlyingTypeResolveException(string message, Exception innerException) : base(message, innerException)
{
}
protected EnumUnderlyingTypeResolveException(SerializationInfo info, StreamingContext context) : base(info, context) [Serializable]
{ public class PEFileNotSupportedException : Exception
} {
public PEFileNotSupportedException() { }
public PEFileNotSupportedException(string message) : base(message) { }
public PEFileNotSupportedException(string message, Exception inner) : base(message, inner) { }
protected PEFileNotSupportedException(
SerializationInfo info,
StreamingContext context) : base(info, context) { }
} }
} }

2
ICSharpCode.Decompiler/Metadata/PEFile.cs

@ -62,7 +62,7 @@ namespace ICSharpCode.Decompiler.Metadata
this.FileName = fileName ?? throw new ArgumentNullException(nameof(fileName)); this.FileName = fileName ?? throw new ArgumentNullException(nameof(fileName));
this.Reader = reader ?? throw new ArgumentNullException(nameof(reader)); this.Reader = reader ?? throw new ArgumentNullException(nameof(reader));
if (!reader.HasMetadata) if (!reader.HasMetadata)
throw new ArgumentException("PE file does not contain any metadata!"); throw new PEFileNotSupportedException("PE file does not contain any managed metadata.");
this.Metadata = reader.GetMetadataReader(); this.Metadata = reader.GetMetadataReader();
} }

3
ILSpy/TreeNodes/AssemblyTreeNode.cs

@ -264,6 +264,9 @@ namespace ICSharpCode.ILSpy.TreeNodes
case DirectoryNotFoundException dirNotFound: case DirectoryNotFoundException dirNotFound:
HandleException(dirNotFound, "The directory was not found."); HandleException(dirNotFound, "The directory was not found.");
return; return;
case PEFileNotSupportedException notSupported:
HandleException(notSupported, notSupported.Message);
return;
default: default:
throw; throw;
} }

Loading…
Cancel
Save