Browse Source

Fix #1777 and part 2 of #1776: Add more null checks

pull/1790/head
Siegfried Pammer 7 years ago
parent
commit
e104f4ce6e
  1. 5
      ILSpy/MainWindow.xaml.cs
  2. 10
      ILSpy/TextView/DecompilerTextView.cs

5
ILSpy/MainWindow.xaml.cs

@ -399,6 +399,11 @@ namespace ICSharpCode.ILSpy
static bool CanResolveTypeInPEFile(PEFile module, ITypeReference typeRef, out EntityHandle typeHandle) static bool CanResolveTypeInPEFile(PEFile module, ITypeReference typeRef, out EntityHandle typeHandle)
{ {
if (module == null) {
typeHandle = default;
return false;
}
switch (typeRef) { switch (typeRef) {
case GetPotentiallyNestedClassTypeReference topLevelType: case GetPotentiallyNestedClassTypeReference topLevelType:
typeHandle = topLevelType.ResolveInPEFile(module); typeHandle = topLevelType.ResolveInPEFile(module);

10
ILSpy/TextView/DecompilerTextView.cs

@ -345,14 +345,20 @@ namespace ICSharpCode.ILSpy.TextView
} }
return new FlowDocumentTooltip(renderer.CreateDocument()); return new FlowDocumentTooltip(renderer.CreateDocument());
} else if (segment.Reference is IEntity entity) { } else if (segment.Reference is IEntity entity) {
return new FlowDocumentTooltip(CreateTooltipForEntity(entity)); var document = CreateTooltipForEntity(entity);
if (document == null)
return null;
return new FlowDocumentTooltip(document);
} else if (segment.Reference is ValueTuple<PEFile, System.Reflection.Metadata.EntityHandle> unresolvedEntity) { } else if (segment.Reference is ValueTuple<PEFile, System.Reflection.Metadata.EntityHandle> unresolvedEntity) {
var typeSystem = new DecompilerTypeSystem(unresolvedEntity.Item1, unresolvedEntity.Item1.GetAssemblyResolver(), TypeSystemOptions.Default | TypeSystemOptions.Uncached); var typeSystem = new DecompilerTypeSystem(unresolvedEntity.Item1, unresolvedEntity.Item1.GetAssemblyResolver(), TypeSystemOptions.Default | TypeSystemOptions.Uncached);
try { try {
IEntity resolved = typeSystem.MainModule.ResolveEntity(unresolvedEntity.Item2); IEntity resolved = typeSystem.MainModule.ResolveEntity(unresolvedEntity.Item2);
if (resolved == null) if (resolved == null)
return null; return null;
return new FlowDocumentTooltip(CreateTooltipForEntity(resolved)); var document = CreateTooltipForEntity(resolved);
if (document == null)
return null;
return new FlowDocumentTooltip(document);
} catch (BadImageFormatException) { } catch (BadImageFormatException) {
return null; return null;
} }

Loading…
Cancel
Save