Skip to content

Commit af594e4

Browse files
Do not crash on files that contain no managed metadata.
1 parent 38247fe commit af594e4

3 files changed

Lines changed: 21 additions & 15 deletions

File tree

ICSharpCode.Decompiler/Metadata/EnumUnderlyingTypeResolveException.cs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,25 @@
2323

2424
namespace ICSharpCode.Decompiler.Metadata
2525
{
26+
[Serializable]
2627
public class EnumUnderlyingTypeResolveException : Exception
2728
{
28-
public EnumUnderlyingTypeResolveException()
29-
{
30-
}
31-
32-
public EnumUnderlyingTypeResolveException(string message) : base(message)
33-
{
34-
}
35-
36-
public EnumUnderlyingTypeResolveException(string message, Exception innerException) : base(message, innerException)
37-
{
38-
}
29+
public EnumUnderlyingTypeResolveException() { }
30+
public EnumUnderlyingTypeResolveException(string message) : base(message) { }
31+
public EnumUnderlyingTypeResolveException(string message, Exception inner) : base(message, inner) { }
32+
protected EnumUnderlyingTypeResolveException(
33+
SerializationInfo info,
34+
StreamingContext context) : base(info, context) { }
35+
}
3936

40-
protected EnumUnderlyingTypeResolveException(SerializationInfo info, StreamingContext context) : base(info, context)
41-
{
42-
}
37+
[Serializable]
38+
public class PEFileNotSupportedException : Exception
39+
{
40+
public PEFileNotSupportedException() { }
41+
public PEFileNotSupportedException(string message) : base(message) { }
42+
public PEFileNotSupportedException(string message, Exception inner) : base(message, inner) { }
43+
protected PEFileNotSupportedException(
44+
SerializationInfo info,
45+
StreamingContext context) : base(info, context) { }
4346
}
4447
}

ICSharpCode.Decompiler/Metadata/PEFile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public PEFile(string fileName, PEReader reader)
6262
this.FileName = fileName ?? throw new ArgumentNullException(nameof(fileName));
6363
this.Reader = reader ?? throw new ArgumentNullException(nameof(reader));
6464
if (!reader.HasMetadata)
65-
throw new ArgumentException("PE file does not contain any metadata!");
65+
throw new PEFileNotSupportedException("PE file does not contain any managed metadata.");
6666
this.Metadata = reader.GetMetadataReader();
6767
}
6868

ILSpy/TreeNodes/AssemblyTreeNode.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ void HandleException(Exception ex, string message)
264264
case DirectoryNotFoundException dirNotFound:
265265
HandleException(dirNotFound, "The directory was not found.");
266266
return;
267+
case PEFileNotSupportedException notSupported:
268+
HandleException(notSupported, notSupported.Message);
269+
return;
267270
default:
268271
throw;
269272
}

0 commit comments

Comments
 (0)