Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async await on dynamic expression is not detected. #1388

Open
greenozon opened this issue Jan 8, 2019 · 2 comments
Open

Async await on dynamic expression is not detected. #1388

greenozon opened this issue Jan 8, 2019 · 2 comments
Labels
Async C# Decompiler The decompiler engine itself Enhancement Areas for improvement

Comments

@greenozon
Copy link

ILSpy version 4.0.0.4518-rc1

Error decompiling Microsoft.VisualStudio.Settings.PubSubReceiver.SubscribeAsync
 ---> System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
   at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource) in offset 46
   at System.Collections.Generic.List`1.get_Item(Int32 index) in offset 0
   at ICSharpCode.Decompiler.IL.InstructionCollection`1.get_Item(Int32 index) in offset 1
   at ICSharpCode.Decompiler.IL.ControlFlow.AsyncAwaitDecompiler.AnalyzeAwaitBlock(Block block, ILVariable& awaiter, IField& awaiterField, Int32& state) in offset 176
   at ICSharpCode.Decompiler.IL.ControlFlow.AsyncAwaitDecompiler.AnalyzeStateMachine(ILFunction function) in offset 228
   at ICSharpCode.Decompiler.IL.ControlFlow.AsyncAwaitDecompiler.Run(ILFunction function, ILTransformContext context) in offset 163
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DecompileBody(IMethod method, EntityDeclaration entityDecl, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in offset 581
-- continuing with outer exception (ICSharpCode.Decompiler.DecompilerException) --
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DecompileBody(IMethod method, EntityDeclaration entityDecl, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in offset 1068
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DoDecompile(IMethod method, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in offset 249
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DoDecompile(ITypeDefinition typeDef, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in offset 747
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DoDecompileTypes(IEnumerable`1 types, DecompileRun decompileRun, ITypeResolveContext decompilationContext, SyntaxTree syntaxTree) in offset 219
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DecompileTypes(IEnumerable`1 types) in offset 201
   at ICSharpCode.Decompiler.CSharp.WholeProjectDecompiler.<>c__DisplayClass30_0.<WriteCodeFilesInProject>b__2(IGrouping`2 file) in offset 68
   at System.Threading.Tasks.Parallel.<>c__DisplayClass17_0`1.<ForWorker>b__1() in offset 589
   at System.Threading.Tasks.Task.InnerInvokeWithArg(Task childTask) in offset 6
   at System.Threading.Tasks.Task.<>c__DisplayClass176_0.<ExecuteSelfReplicating>b__0(Object) in offset 134

target: https://www.sendspace.com/file/gjwrkb

@dgrunwald
Copy link
Member

The cause seems to be await dynamicExpression;
The C# compiler uses a completely different code pattern here than for normal awaits, because the INotifyCompletion/ICriticalNotifyCompletion distinction now has to happen at run-time instead of compile-time.
We are fixing the crash, but adjusting the async/await transform is more complicated.

@siegfriedpammer siegfriedpammer changed the title v.4.rc1: ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index Async await on dynamic expression is not detected. Feb 15, 2019
@siegfriedpammer
Copy link
Member

A simple test case:

class Program
{
    dynamic GetDynamic()
    {
        return null;
    }

    public async Task<dynamic> TestDynamicWithAsync()
    {
        dynamic value = await GetDynamic();
        value.UseMe();
        return value;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Async C# Decompiler The decompiler engine itself Enhancement Areas for improvement
Projects
None yet
Development

No branches or pull requests

3 participants