What is the reason for the following code throwing this exception saying "Expression has to be MethodCallExpression. I thought calling an Action IS that..
Action startBouncePolling = new Action(async () =>
{
});
BackgroundJob.Enqueue(() => startBouncePolling());
Signature of Enqueue is one parameter of Expression<Action>
When you call startBouncePolling(), you're not calling a method. startBouncePolling is not a method, it's a delegate. So you are actually invoking a delegate.
Therefore, the body of the lambda expression () => startBouncePolling() ends up being a InvocationExpression, not a MethodCallExpression.
If you use a method instead of a delegate, for example:
public async Task StartBouncePolling()
{
}
...
BackgroundJob.Enqueue(() => StartBouncePolling());
then the body would be a MethodCallExpression.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With