icsharpcode/ILSpy

`InvalidOperationException` thrown when reading debug metadata files

steviegt6 opened this issue · 3 comments

Steps to reproduce

  1. Drag a PDB file with no Module table into ILSpy (such as the one attached).
  2. Attempt to open it or to perform a search (or any other operation that triggers a decompilation).
  3. Observe the error.

Error message shown

The following is printed in a new tab when attempting to view a PDB file that causes this exception to occur:

System.InvalidOperationException: Standalone debug metadata image doesn't contain Module table.
   at System.Reflection.Metadata.MetadataReader.GetModuleDefinition()
   at ICSharpCode.ILSpy.Language.DecompileAssembly(LoadedAssembly assembly, ITextOutput output, DecompilationOptions options)
   at ICSharpCode.ILSpy.CSharpLanguage.DecompileAssembly(LoadedAssembly assembly, ITextOutput output, DecompilationOptions options)
   at ICSharpCode.ILSpy.TreeNodes.AssemblyTreeNode.Decompile(Language language, ITextOutput output, DecompilationOptions options)
   at ICSharpCode.ILSpy.TextView.DecompilerTextView.DecompileNodes(DecompilationContext context, ITextOutput textOutput)
   at ICSharpCode.ILSpy.TextView.DecompilerTextView.<>c__DisplayClass53_0.<DecompileAsync>b__0()

A similar message is provided when attempting a search (which is why this is annoying):
image

Details

  • Product in use: ILSpy
  • Version in use: 9.0.0.7660-preview2
  • I have attached a PDB file sourced from the latest version of JetBrains Rider's ReSharperHost as that's what I was messing with when encountering this error (the associated library in question is a separate, Apache 2.0 project, so there should be no issues legally speaking with sharing this file).
  • I'd be happy to submit a patch myself fixing this issue but I'm unsure of the preferred approach.
  • This error is consistent with other PDB files provided by ReSharperHost, I have not independently tested it on files produced by other means.
  • My biggest concern is that this prevents me from performing a search on many read files without manually going through and removing the files causing the error. At minimum I'd like a solution that allows the search functionality to still function.

Appccelerate.StateMachine.zip

The sample PDB has been provided as a ZIP archive because GitHub arbitrarily decides to limit allowed file extensions.

The line that invokes GetModuleDefinition when attempting to view the decompilation view is as follows:
image

The line that invokes GetModuleDefinition when attempting a search is as follows:
image

In the second scenario, ILSpy is smart enough to handle providing a fallback name when a BadImageFormatException is thrown; perhaps this should be the preferred behavior in this case too?

Thank you for reporting this!

Of course! Thank you so much!