question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Closure in async lambda throw InvalidOperationException

See original GitHub issue

The following snippet throws InvalidOperationException with message Cannot close over byref parameter '' referenced in lambda ''

        var lambda = CodeGenerator.AsyncLambda<Func<Task<string>>>(_ =>
        {
            var hello = CodeGenerator.DeclareVariable<string>("hello");
            var foo = CodeGenerator.DeclareVariable<Func<string>>("foo");
            CodeGenerator.Statement(Expression.Assign(hello, Expression.Constant("hello")));
            CodeGenerator.Statement(Expression.Assign(foo, Expression.Lambda<Func<string>>(hello)));
            CodeGenerator.Return(Expression.Invoke(foo));
        });

        var compiled = lambda.Compile();

I want to use the AsyncLambda to generate async code from my own DSL but I havn’t been able to work around the above issue yet.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
saknocommented, Nov 8, 2022
1reaction
Cookecommented, Nov 8, 2022

@sakno it works as expected. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

An exception thrown in an async lambda isn't being caught ...
If I use an async lambda in my Test, then what happens is the Exception is thrown at the expected target, and then...
Read more >
AWS Lambda function errors in C# - ...
This page describes how to view Lambda function invocation errors for the C# ... In the initialization phase, exceptions can be thrown for...
Read more >
Handling Async Await Exceptions
Next post I'll explore of using async lambdas and how you need to pay close attention in order to avoid creating a void...
Read more >
Replacing ThrowsAsync with a composable async alternative
Today's Assert.ThrowsAsync and related methods do sync-over-async. This means they convert an async operation into a synchronous one.
Read more >
Invalid operation. The connection is closed.
hello All, I am getting this error when calling a small function. I am calling this function twice. Below is my code: public...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found