ILSpy icon indicating copy to clipboard operation
ILSpy copied to clipboard

Async methods returning ValueTask are not decompiled

Open jasonmeisel opened this issue 7 years ago • 4 comments

When I right click an assembly and "save code" to create a project, it doesn't output the generated classes and methods that async methods reference.

I can see the generated code if I turn on "show all types and members", but it doesn't save the code to files. I get the same result using the ilspycmd utility.

Is it possible to output the generated code as well, so it generates a functional csproj?

jasonmeisel avatar Aug 20 '19 00:08 jasonmeisel

Actually the async state machine should be transformed back into a compilable method. Would you be able to provide the assembly, so that we can take a look and fix the problem? Thank you very much!

siegfriedpammer avatar Aug 20 '19 05:08 siegfriedpammer

I attempted to create a simple repro assembly, but in that assembly you were correct - it decompiled into an async method! This was the case unless I switched the C# version to 4.0 (pre-async), and then it output the generated code. In fact, then it also saved the generated code using "save code" 😁

The assembly I'm trying to decompile is System.Private.CoreLib.dll from https://github.com/dotnet/coreclr/tree/master/src/System.Private.CoreLib. In it, System.IO.FileStream.DisposeAsyncCore was having the issue (among others).

Luckily, switching the version to 4.0 on that assembly also fixes the issue! So there's definitely a bug in that it's not decompiling back to async correctly (and references the generated code it doesn't actually output) when set to 7.0 or 8.0 with that assembly. However, this work-around works for me 👍

jasonmeisel avatar Aug 20 '19 19:08 jasonmeisel

Example: System.Private.CoreLib.dll from .NET Core 3.0 preview 7 or later. Method: System.IO.FileStream.DisposeAsyncCore

siegfriedpammer avatar Aug 20 '19 19:08 siegfriedpammer

ValueTask depends on the "Generalized async return types" C# 7 feature, which ILSpy does not implement yet. See language support status: #829

dgrunwald avatar Aug 20 '19 20:08 dgrunwald