When enqueing job: "lambda expression with statement body cannot be converted to an expression tree"

I’m getting this error trying to enqueue a job. I have read a topic that was sort of helpful but not really (Generate a MethodCallExpression to pass to HangFire Enqueue - #2 by silentbobbert)

Here’s what my code looks like

I hope you can tell what I’m trying to do, but I’ve gone round and around in circles trying to make this work. I’m trying to use the REST API provided by Ghost Inspector to run automated browser tests. Since those tests can run for several minutes, HangFire is an obvious choice, but like I say I don’t really understand what you can and can’t do in the Enqueue method call argument. I’ve read a lot, but I don’t really get it, sorry.

Just rewrite it without method body: BackgroundJob.Enqueue(() => RunTest(null, taskInfo, null))

1 Like