icsharpcode / ILSpy

.NET Decompiler with support for PDB generation, ReadyToRun, Metadata (&more) - cross-platform!
21.48k stars 3.35k forks source link

System.IndexOutOfRangeException: Index was outside the bounds of the array. - missing info on assembly being decompiled #3309

Open greenozon opened 1 day ago

greenozon commented 1 day ago

Input code

get latest ILSpy debug CI build d-n-d all files insdie try to decompile itself "eat-your-own-dogfood"

it was doing something for minute or two (not showing info on what assemlby/type being decompiled)

The quesiton is - why does it not add the info on assembly beding decompiled? it is not possible to deduce which one got asserted provided that I was saving lots of assemblies at once... :(

Erroneous output

System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at ICSharpCode.Decompiler.CSharp.Transforms.TransformFieldAndConstructorInitializers.HandleInstanceFieldInitializers(IEnumerable`1 members) in /_/ICSharpCode.Decompiler/CSharp/Transforms/TransformFieldAndConstructorInitializers.cs:line 206
   at ICSharpCode.Decompiler.CSharp.Transforms.TransformFieldAndConstructorInitializers.VisitTypeDeclaration(TypeDeclaration typeDeclaration) in /_/ICSharpCode.Decompiler/CSharp/Transforms/TransformFieldAndConstructorInitializers.cs:line 168
   at ICSharpCode.Decompiler.CSharp.Syntax.TypeDeclaration.AcceptVisitor(IAstVisitor visitor) in /_/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/TypeDeclaration.cs:line 137
   at ICSharpCode.Decompiler.CSharp.Syntax.DepthFirstAstVisitor.VisitChildren(AstNode node) in /_/ICSharpCode.Decompiler/CSharp/Syntax/DepthFirstAstVisitor.cs:line 43
   at ICSharpCode.Decompiler.CSharp.Syntax.DepthFirstAstVisitor.VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration) in /_/ICSharpCode.Decompiler/CSharp/Syntax/DepthFirstAstVisitor.cs:line 142
   at ICSharpCode.Decompiler.CSharp.Syntax.NamespaceDeclaration.AcceptVisitor(IAstVisitor visitor) in /_/ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/NamespaceDeclaration.cs:line 140
   at ICSharpCode.Decompiler.CSharp.Syntax.DepthFirstAstVisitor.VisitChildren(AstNode node) in /_/ICSharpCode.Decompiler/CSharp/Syntax/DepthFirstAstVisitor.cs:line 43
   at ICSharpCode.Decompiler.CSharp.Syntax.DepthFirstAstVisitor.VisitSyntaxTree(SyntaxTree syntaxTree) in /_/ICSharpCode.Decompiler/CSharp/Syntax/DepthFirstAstVisitor.cs:line 57
   at ICSharpCode.Decompiler.CSharp.Syntax.SyntaxTree.AcceptVisitor(IAstVisitor visitor) in /_/ICSharpCode.Decompiler/CSharp/Syntax/SyntaxTree.cs:line 128
   at ICSharpCode.Decompiler.CSharp.Transforms.TransformFieldAndConstructorInitializers.Run(AstNode node, TransformContext context) in /_/ICSharpCode.Decompiler/CSharp/Transforms/TransformFieldAndConstructorInitializers.cs:line 55
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.RunTransforms(AstNode rootNode, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in /_/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs:line 570
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DecompileWholeModuleAsSingleFile(Boolean sortTypes) in /_/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs:line 690
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DecompileWholeModuleAsSingleFile() in /_/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs:line 666
   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__DisplayClass66_0.<SaveToDiskAsync>b__0()

Expectation: ILSpy clearly shows what assembly fails, what type/token.. etc

image

Details

siegfriedpammer commented 21 hours ago

I cannot reproduce this... in the stack trace we can see DecompileWholeModuleAsSingleFile, which is only executed, if FullDecompilation is set to true, which is only the case if you select "Save Code" and the "single file (.cs)" option, which is not available, when multiple assemblies are selected.

greenozon commented 9 hours ago

OK, I"ll try to repro again and record more detailed steps