ILSpy crashes when it parses deconstruction constructs
Opened this issue · 0 comments
igorpyan commented
Steps to reproduce
- Create and compile the code below using .NET 8.
- Try to decompile it with ILSpy:
ilspycmd.exe -p -o .\decompiled2 ConsoleApp1.dll
- A crash occurs
Code:
ConsoleApp1:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
Program.cs:
class Test
{
private WorkerProfileBounds SqlDbBounds => new(1024, 4096);
public readonly record struct WorkerProfileInfo(WorkerProfile WorkerProfile, WorkerProfileBounds Bounds);
public readonly record struct WorkerProfileBounds(ulong SmallProfileUpperBound, ulong LargeProfileLowerBound);
public enum WorkerProfile
{
Small,
Medium,
Large,
Archive
}
public WorkerProfileInfo GetDeploymentWorkerProfileForSql(ulong? protectedResourceSize)
=> GetWorkerProfileInfoForSize(protectedResourceSize, SqlDbBounds);
private static WorkerProfileInfo GetWorkerProfileInfoForSize(ulong? protectedResourceSize, WorkerProfileBounds bounds)
=> new(WorkerProfile.Small, bounds);
}
class Program {
static void Main() {
Test test = new Test();
var (workerProfile, (smallBound, largeBound)) = test.GetDeploymentWorkerProfileForSql(777);
Console.WriteLine(workerProfile.ToString());
Console.WriteLine(smallBound);
Console.WriteLine(largeBound);
}
}
Error message shown
System.AggregateException: One or more errors occurred. (Error decompiling @06000005 Program.Main)
---> Error decompiling @06000005 Program.Main
in assembly "ConsoleApp1.dll"
---> System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
at System.ThrowHelper.ThrowArgumentOutOfRange_IndexException() in offset 0
at ICSharpCode.Decompiler.CSharp.ExpressionBuilder.<VisitDeconstructInstruction>g__ConstructTuple|159_0(MatchInstruction matchInstruction, <>c__DisplayClass159_0&) in ExpressionBuilder.cs:line 4496
at ICSharpCode.Decompiler.CSharp.ExpressionBuilder.VisitDeconstructInstruction(DeconstructInstruction inst, TranslationContext context) in ExpressionBuilder.cs:line 4481
at ICSharpCode.Decompiler.IL.DeconstructInstruction.AcceptVisitor[C,T](ILVisitor`2 visitor, C context) in Instructions.cs:line 6729
at ICSharpCode.Decompiler.CSharp.ExpressionBuilder.Translate(ILInstruction inst, IType typeHint) in ExpressionBuilder.cs:line 163
at ICSharpCode.Decompiler.CSharp.StatementBuilder.Default(ILInstruction inst) in StatementBuilder.cs:line 89
at ICSharpCode.Decompiler.IL.ILVisitor`1.VisitDeconstructInstruction(DeconstructInstruction inst) in Instructions.cs:line 7614
at ICSharpCode.Decompiler.IL.DeconstructInstruction.AcceptVisitor[T](ILVisitor`1 visitor) in Instructions.cs:line 6725
at ICSharpCode.Decompiler.CSharp.StatementBuilder.Convert(ILInstruction inst) in StatementBuilder.cs:line 78
at ICSharpCode.Decompiler.CSharp.StatementBuilder.ConvertBlockContainer(BlockStatement blockStatement, BlockContainer container, IEnumerable`1 blocks, Boolean isLoop) in StatementBuilder.cs:line 1429
at ICSharpCode.Decompiler.CSharp.StatementBuilder.ConvertBlockContainer(BlockContainer container, Boolean isLoop) in StatementBuilder.cs:line 1367
at ICSharpCode.Decompiler.CSharp.StatementBuilder.VisitBlockContainer(BlockContainer container) in StatementBuilder.cs:line 1253
at ICSharpCode.Decompiler.IL.BlockContainer.AcceptVisitor[T](ILVisitor`1 visitor) in Instructions.cs:line 850
at ICSharpCode.Decompiler.CSharp.StatementBuilder.Convert(ILInstruction inst) in StatementBuilder.cs:line 78
at ICSharpCode.Decompiler.CSharp.StatementBuilder.ConvertAsBlock(ILInstruction inst) in StatementBuilder.cs:line 83
at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DecompileBody(IMethod method, EntityDeclaration entityDecl, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in CSharpDecompiler.cs:line 1750
-- continuing with outer exception (ICSharpCode.Decompiler.DecompilerException) --
at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DecompileBody(IMethod method, EntityDeclaration entityDecl, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in CSharpDecompiler.cs:line 1773
at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DoDecompile(IMethod method, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in CSharpDecompiler.cs:line 1622
at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.<>c__DisplayClass74_0.<DoDecompile>g__DoDecompileMember|0(IEntity entity, RecordDecompiler recordDecompiler, PartialTypeInfo partialType) in CSharpDecompiler.cs:line 1497
at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DoDecompile(ITypeDefinition typeDef, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in CSharpDecompiler.cs:line 1364
at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DoDecompileTypes(IEnumerable`1 types, DecompileRun decompileRun, ITypeResolveContext decompilationContext, SyntaxTree syntaxTree) in CSharpDecompiler.cs:line 651
at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DecompileTypes(IEnumerable`1 types) in CSharpDecompiler.cs:line 950
at ICSharpCode.Decompiler.CSharp.ProjectDecompiler.WholeProjectDecompiler.<>c__DisplayClass46_0.<WriteCodeFilesInProject>b__5(IGrouping`2 file) in WholeProjectDecompiler.cs:line 274
at System.Threading.Tasks.Parallel.<>c__DisplayClass44_0`2.<PartitionerForEachWorker>b__1(IEnumerator& partitionState, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion) in offset 259
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() in offset 17
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Exception source) in offset 0
at System.Threading.Tasks.Parallel.<>c__DisplayClass44_0`2.<PartitionerForEachWorker>b__1(IEnumerator& partitionState, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion) in offset 609
at System.Threading.Tasks.TaskReplicator.Replica`1.ExecuteAction(Boolean& yieldedBeforeCompletion) in offset 0
at System.Threading.Tasks.TaskReplicator.Replica.Execute() in offset 0
--- End of inner exception stack trace ---
at System.Threading.Tasks.TaskReplicator.Run[TState](ReplicatableUserAction`1 action, ParallelOptions options, Boolean stopOnFirstFailure)
at System.Threading.Tasks.Parallel.PartitionerForEachWorker[TSource,TLocal](Partitioner`1 source, ParallelOptions parallelOptions, Action`1 simpleBody, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
--- End of stack trace from previous location ---
at System.Threading.Tasks.Parallel.ThrowSingleCancellationExceptionOrOtherException(ICollection exceptions, CancellationToken cancelToken, Exception otherException)
at System.Threading.Tasks.Parallel.PartitionerForEachWorker[TSource,TLocal](Partitioner`1 source, ParallelOptions parallelOptions, Action`1 simpleBody, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
at System.Threading.Tasks.Parallel.ForEach[TSource](Partitioner`1 source, ParallelOptions parallelOptions, Action`1 body)
at ICSharpCode.Decompiler.CSharp.ProjectDecompiler.WholeProjectDecompiler.<>c__DisplayClass46_0.<WriteCodeFilesInProject>g__ProcessFiles|3(List`1 files) in /_/ICSharpCode.Decompiler/CSharp/ProjectDecompiler/WholeProjectDecompiler.cs:line 255
at ICSharpCode.Decompiler.CSharp.ProjectDecompiler.WholeProjectDecompiler.WriteCodeFilesInProject(PEFile module, IList`1 partialTypes, CancellationToken cancellationToken) in /_/ICSharpCode.Decompiler/CSharp/ProjectDecompiler/WholeProjectDecompiler.cs:line 221
at ICSharpCode.Decompiler.CSharp.ProjectDecompiler.WholeProjectDecompiler.DecompileProject(PEFile moduleDefinition, String targetDirectory, TextWriter projectFileWriter, CancellationToken cancellationToken) in /_/ICSharpCode.Decompiler/CSharp/ProjectDecompiler/WholeProjectDecompiler.cs:line 154
at ICSharpCode.ILSpyCmd.ILSpyCmdProgram.DecompileAsProject(String assemblyFileName, String projectFileName) in D:\a\ILSpy\ILSpy\ICSharpCode.ILSpyCmd\IlspyCmdProgram.cs:line 318
at ICSharpCode.ILSpyCmd.ILSpyCmdProgram.OnExecuteAsync(CommandLineApplication app) in D:\a\ILSpy\ILSpy\ICSharpCode.ILSpyCmd\IlspyCmdProgram.cs:line 147
Details
- ilspycmd: 8.2.0.7535
- Microsoft.NETCore.App 8.0.6