Browse Source

Provide better exceptions and messages in case of errors.

pull/1030/head
Siegfried Pammer 7 years ago
parent
commit
89544864bf
  1. 2
      ICSharpCode.Decompiler/IL/ILReader.cs
  2. 2
      ICSharpCode.Decompiler/IL/Instructions/ILFunction.cs
  3. 2
      ICSharpCode.Decompiler/Metadata/PEFile.cs
  4. 7
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/BamlBinaryReader.cs
  5. 2
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs
  6. 2
      ILSpy/Analyzers/AnalyzeContextMenuEntry.cs
  7. 10
      ILSpy/Analyzers/AnalyzerSearchTreeNode.cs
  8. 6
      ILSpy/Images/Images.cs

2
ICSharpCode.Decompiler/IL/ILReader.cs

@ -1589,7 +1589,7 @@ namespace ICSharpCode.Decompiler.IL
return new LdTypeToken(typeSystem.ResolveAsType(token)); return new LdTypeToken(typeSystem.ResolveAsType(token));
if (token.Kind.IsMemberKind()) if (token.Kind.IsMemberKind())
return new LdMemberToken(typeSystem.ResolveAsMember(token)); return new LdMemberToken(typeSystem.ResolveAsMember(token));
throw new NotImplementedException(); throw new BadImageFormatException("Invalid metadata token for ldtoken instruction.");
} }
} }
} }

2
ICSharpCode.Decompiler/IL/Instructions/ILFunction.cs

@ -100,7 +100,7 @@ namespace ICSharpCode.Decompiler.IL
void CloneVariables() void CloneVariables()
{ {
throw new NotImplementedException(); throw new NotSupportedException("ILFunction.CloneVariables is currently not supported!");
} }
public override void WriteTo(ITextOutput output, ILAstWritingOptions options) public override void WriteTo(ITextOutput output, ILAstWritingOptions options)

2
ICSharpCode.Decompiler/Metadata/PEFile.cs

@ -43,6 +43,8 @@ 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)
throw new ArgumentException("PE file does not contain any metadata!");
this.Metadata = reader.GetMetadataReader(); this.Metadata = reader.GetMetadataReader();
} }

7
ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/BamlBinaryReader.cs

@ -8,7 +8,6 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
{ {
internal class BamlBinaryReader : BinaryReader internal class BamlBinaryReader : BinaryReader
{ {
// Methods
public BamlBinaryReader(Stream stream) public BamlBinaryReader(Stream stream)
: base(stream) : base(stream)
{ {
@ -16,7 +15,8 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
public virtual double ReadCompressedDouble() public virtual double ReadCompressedDouble()
{ {
switch (this.ReadByte()) { byte b = this.ReadByte();
switch (b) {
case 1: case 1:
return 0; return 0;
case 2: case 2:
@ -27,8 +27,9 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
return ReadInt32() * 1E-06; return ReadInt32() * 1E-06;
case 5: case 5:
return this.ReadDouble(); return this.ReadDouble();
default:
throw new BadImageFormatException($"Unexpected byte sequence in ReadCompressedDouble: 0x{b:x}");
} }
throw new NotSupportedException();
} }
public int ReadCompressedInt32() public int ReadCompressedInt32()

2
ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs

@ -467,7 +467,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
int s = reader.ReadInt32(); int s = reader.ReadInt32();
int t = reader.ReadInt32(); int t = reader.ReadInt32();
if (((r != 0x600000) || (s != 0x600000)) || (t != 0x600000)) if (((r != 0x600000) || (s != 0x600000)) || (t != 0x600000))
throw new NotSupportedException(); throw new BadImageFormatException("Magic value mismatch!");
initialized = true; initialized = true;
} }

2
ILSpy/Analyzers/AnalyzeContextMenuEntry.cs

@ -85,7 +85,7 @@ namespace ICSharpCode.ILSpy.Analyzers
AnalyzerTreeView.Instance.ShowOrFocus(new AnalyzedEventTreeNode(ed)); AnalyzerTreeView.Instance.ShowOrFocus(new AnalyzedEventTreeNode(ed));
break; break;
default: default:
throw new NotSupportedException(); throw new ArgumentOutOfRangeException(nameof(entity), $"Entity {entity.GetType().FullName} is not supported.");
} }
} }
} }

10
ILSpy/Analyzers/AnalyzerSearchTreeNode.cs

@ -68,9 +68,13 @@ namespace ICSharpCode.ILSpy.Analyzers
} }
} }
AnalyzerTreeNode EntityTreeNodeFactory(IEntity result) AnalyzerTreeNode EntityTreeNodeFactory(IEntity entity)
{ {
switch (result) { if (entity == null) {
throw new ArgumentNullException(nameof(entity));
}
switch (entity) {
case ITypeDefinition td: case ITypeDefinition td:
return new AnalyzedTypeTreeNode(td) { return new AnalyzedTypeTreeNode(td) {
Language = this.Language Language = this.Language
@ -92,7 +96,7 @@ namespace ICSharpCode.ILSpy.Analyzers
Language = this.Language Language = this.Language
}; };
default: default:
throw new NotSupportedException(); throw new ArgumentOutOfRangeException(nameof(entity), $"Entity {entity.GetType().FullName} is not supported.");
} }
} }

6
ILSpy/Images/Images.cs

@ -168,7 +168,7 @@ namespace ICSharpCode.ILSpy
baseImage = Images.StaticClass; baseImage = Images.StaticClass;
break; break;
default: default:
throw new NotSupportedException(); throw new ArgumentOutOfRangeException(nameof(icon), $"TypeIcon.{icon} is not supported!");
} }
return baseImage; return baseImage;
@ -238,7 +238,7 @@ namespace ICSharpCode.ILSpy
baseImage = Images.Event; baseImage = Images.Event;
break; break;
default: default:
throw new NotSupportedException(); throw new ArgumentOutOfRangeException(nameof(icon), $"MemberIcon.{icon} is not supported!");
} }
return baseImage; return baseImage;
@ -303,7 +303,7 @@ namespace ICSharpCode.ILSpy
overlayImage = Images.OverlayCompilerControlled; overlayImage = Images.OverlayCompilerControlled;
break; break;
default: default:
throw new NotSupportedException(); throw new ArgumentOutOfRangeException(nameof(overlay), $"AccessOverlayIcon.{overlay} is not supported!");
} }
return overlayImage; return overlayImage;
} }

Loading…
Cancel
Save