diff --git a/ICSharpCode.Decompiler/Metadata/MetadataFile.cs b/ICSharpCode.Decompiler/Metadata/MetadataFile.cs index c92c0e061c..b8c284027d 100644 --- a/ICSharpCode.Decompiler/Metadata/MetadataFile.cs +++ b/ICSharpCode.Decompiler/Metadata/MetadataFile.cs @@ -61,6 +61,7 @@ public enum MetadataFileKind public virtual int MetadataOffset { get; } public virtual bool IsEmbedded { get; } + public virtual bool IsMetadataOnly { get; } = true; public bool IsAssembly => Metadata.IsAssembly; diff --git a/ICSharpCode.Decompiler/Metadata/PEFile.cs b/ICSharpCode.Decompiler/Metadata/PEFile.cs index 9277ed71f1..40e88534d8 100644 --- a/ICSharpCode.Decompiler/Metadata/PEFile.cs +++ b/ICSharpCode.Decompiler/Metadata/PEFile.cs @@ -53,6 +53,7 @@ public PEFile(string fileName, PEReader reader, MetadataReaderOptions metadataOp public override bool IsEmbedded => false; public override int MetadataOffset => Reader.PEHeaders.MetadataStartOffset; + public override bool IsMetadataOnly => false; public void Dispose() { diff --git a/ICSharpCode.Decompiler/Metadata/WebCilFile.cs b/ICSharpCode.Decompiler/Metadata/WebCilFile.cs index d862c261bb..b93033c323 100644 --- a/ICSharpCode.Decompiler/Metadata/WebCilFile.cs +++ b/ICSharpCode.Decompiler/Metadata/WebCilFile.cs @@ -183,6 +183,7 @@ static unsafe bool TryReadWebCilSegment(BinaryReader reader, out WebcilHeader we } public override int MetadataOffset { get; } + public override bool IsMetadataOnly => false; private static int GetContainingSectionIndex(IEnumerable sections, int rva) { diff --git a/ICSharpCode.ILSpyX/Analyzers/AnalyzerScope.cs b/ICSharpCode.ILSpyX/Analyzers/AnalyzerScope.cs index 8f01faf0f7..290e225bfa 100644 --- a/ICSharpCode.ILSpyX/Analyzers/AnalyzerScope.cs +++ b/ICSharpCode.ILSpyX/Analyzers/AnalyzerScope.cs @@ -72,7 +72,7 @@ public IEnumerable GetAllModules() { 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 @@ IEnumerable GetModuleAndAnyFriends(ITypeDefinition typeScope, Canc 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; diff --git a/ICSharpCode.ILSpyX/LoadedAssembly.cs b/ICSharpCode.ILSpyX/LoadedAssembly.cs index 169012d44a..8f7298c84d 100644 --- a/ICSharpCode.ILSpyX/LoadedAssembly.cs +++ b/ICSharpCode.ILSpyX/LoadedAssembly.cs @@ -211,7 +211,7 @@ public async Task GetMetadataFileAsync() { 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 @@ public async Task GetMetadataFileAsync() 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( diff --git a/ILSpy/TreeNodes/AssemblyTreeNode.cs b/ILSpy/TreeNodes/AssemblyTreeNode.cs index 44969d558f..2449047c74 100644 --- a/ILSpy/TreeNodes/AssemblyTreeNode.cs +++ b/ILSpy/TreeNodes/AssemblyTreeNode.cs @@ -467,7 +467,16 @@ void HandleException(Exception ex, string message) 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) {