Browse Source

Fix #3247: InvalidOperationException thrown when reading debug metadata files

pull/3250/head
Siegfried Pammer 10 months ago
parent
commit
dbd9632f34
  1. 1
      ICSharpCode.Decompiler/Metadata/MetadataFile.cs
  2. 1
      ICSharpCode.Decompiler/Metadata/PEFile.cs
  3. 1
      ICSharpCode.Decompiler/Metadata/WebCilFile.cs
  4. 4
      ICSharpCode.ILSpyX/Analyzers/AnalyzerScope.cs
  5. 4
      ICSharpCode.ILSpyX/LoadedAssembly.cs
  6. 11
      ILSpy/TreeNodes/AssemblyTreeNode.cs

1
ICSharpCode.Decompiler/Metadata/MetadataFile.cs

@ -61,6 +61,7 @@ namespace ICSharpCode.Decompiler.Metadata @@ -61,6 +61,7 @@ namespace ICSharpCode.Decompiler.Metadata
public virtual int MetadataOffset { get; }
public virtual bool IsEmbedded { get; }
public virtual bool IsMetadataOnly { get; } = true;
public bool IsAssembly => Metadata.IsAssembly;

1
ICSharpCode.Decompiler/Metadata/PEFile.cs

@ -53,6 +53,7 @@ namespace ICSharpCode.Decompiler.Metadata @@ -53,6 +53,7 @@ namespace ICSharpCode.Decompiler.Metadata
public override bool IsEmbedded => false;
public override int MetadataOffset => Reader.PEHeaders.MetadataStartOffset;
public override bool IsMetadataOnly => false;
public void Dispose()
{

1
ICSharpCode.Decompiler/Metadata/WebCilFile.cs

@ -183,6 +183,7 @@ namespace ICSharpCode.Decompiler.Metadata @@ -183,6 +183,7 @@ namespace ICSharpCode.Decompiler.Metadata
}
public override int MetadataOffset { get; }
public override bool IsMetadataOnly => false;
private static int GetContainingSectionIndex(IEnumerable<SectionHeader> sections, int rva)
{

4
ICSharpCode.ILSpyX/Analyzers/AnalyzerScope.cs

@ -72,7 +72,7 @@ namespace ICSharpCode.ILSpyX.Analyzers @@ -72,7 +72,7 @@ namespace ICSharpCode.ILSpyX.Analyzers
{
return assemblyListSnapshot.GetAllAssembliesAsync().GetAwaiter().GetResult()
.Select(asm => asm.GetMetadataFileOrNull())
.Where(x => x != null)!;
.Where(x => x != null && !x.IsMetadataOnly)!;
}
public DecompilerTypeSystem ConstructTypeSystem(MetadataFile module)
@ -207,7 +207,7 @@ namespace ICSharpCode.ILSpyX.Analyzers @@ -207,7 +207,7 @@ namespace ICSharpCode.ILSpyX.Analyzers
if (friendAssemblies.Contains(assembly.ShortName))
{
var module = assembly.GetMetadataFileOrNull();
if (module == null)
if (module == null || module.IsMetadataOnly)
continue;
if (ModuleReferencesScopeType(module.Metadata, typeScope.Name, typeScope.Namespace))
yield return module;

4
ICSharpCode.ILSpyX/LoadedAssembly.cs

@ -211,7 +211,7 @@ namespace ICSharpCode.ILSpyX @@ -211,7 +211,7 @@ namespace ICSharpCode.ILSpyX
{
return LazyInitializer.EnsureInitialized(ref this.typeSystem, () => {
var module = GetMetadataFileOrNull();
if (module == null)
if (module == null || module.IsMetadataOnly)
return null!;
return new SimpleCompilation(
module.WithOptions(TypeSystemOptions.Default | TypeSystemOptions.Uncached | TypeSystemOptions.KeepModifiers),
@ -230,7 +230,7 @@ namespace ICSharpCode.ILSpyX @@ -230,7 +230,7 @@ namespace ICSharpCode.ILSpyX
if (typeSystemWithOptions != null && options == currentTypeSystemOptions)
return typeSystemWithOptions;
var module = GetMetadataFileOrNull();
if (module == null)
if (module == null || module.IsMetadataOnly)
return null;
currentTypeSystemOptions = options;
return typeSystemWithOptions = new SimpleCompilation(

11
ILSpy/TreeNodes/AssemblyTreeNode.cs

@ -467,7 +467,16 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -467,7 +467,16 @@ namespace ICSharpCode.ILSpy.TreeNodes
var loadResult = LoadedAssembly.GetLoadResultAsync().GetAwaiter().GetResult();
if (loadResult.MetadataFile != null)
{
language.DecompileAssembly(LoadedAssembly, output, options);
switch (loadResult.MetadataFile.Kind)
{
case MetadataFile.MetadataFileKind.ProgramDebugDatabase:
case MetadataFile.MetadataFileKind.Metadata:
output.WriteLine("// " + LoadedAssembly.FileName);
break;
default:
language.DecompileAssembly(LoadedAssembly, output, options);
break;
}
}
else if (loadResult.Package != null)
{

Loading…
Cancel
Save