# Anonymous functions, delegates and lambda expressions aren't supported in job method parameters

**URL:** <https://discuss.hangfire.io/t/anonymous-functions-delegates-and-lambda-expressions-arent-supported-in-job-method-parameters/10256>\
**Category:** bug?\
**Tags:** recurring, configuration, sql-server, aspnetcore\
**Created:** [September 20, 2023, 8:09am UTC](https://discuss.hangfire.io/t/anonymous-functions-delegates-and-lambda-expressions-arent-supported-in-job-method-parameters/10256 "2023-09-20T08:09:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![S-alireza-alavi](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/s-alireza-alavi/32/3482_2.png) [@S-alireza-alavi](https://discuss.hangfire.io/u/S-alireza-alavi)\
**Post date:** [September 20, 2023, 8:09am UTC](https://discuss.hangfire.io/t/anonymous-functions-delegates-and-lambda-expressions-arent-supported-in-job-method-parameters/10256/1 "2023-09-20T08:09:49Z")

</div>

I’m using Hangfire for first time on a .Net Core Application… I’ve wrote a Job like this:

using MyTask.Data;  
using MyTask.Models;

namespace MyTask  
{  
public class CandleStickJob  
{  
private readonly ILogger \_logger;  
private readonly CandleStickDbContext \_context;

```
    public CandleStickJob(ILogger<CandleStickJob> logger, CandleStickDbContext context)
    {
        _logger = logger;
        _context = context;
    }

    public void CalculateAvgPriceJob()
    {
        try
        {
            var candleSticks = _context.CandleSticks.ToList();

            foreach (var candleStick in candleSticks)
            {
                double avgPrice = (candleStick.Low + candleStick.High) / 2.0;

                candleStick.AvgPrice = avgPrice;
            }

            _context.SaveChanges();

            _logger.LogInformation("Successfully updated AvgPrice for all CandleSticks.");
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Error occurred while calculating AvgPrice");
            throw;
        }
    }
}

```

}

And then I’ve used it as a Controller Action Method:

public IActionResult ScheduleAvgPriceJob()  
{  
RecurringJob.AddOrUpdate(“CalculateAvgPrice”, () =\> \_backgroundJobClient.Enqueue(job =\> job.CalculateAvgPriceJob()), “\*/10 \* \* \* \* \*”);

```
        return RedirectToAction(nameof(Index));
    }

```

Problem is when I go to Hangfire Dashboard, in recurring jobs tab there is no services and when I’ve tested it locally with another action method to trigger the method, it throwed me the exception I’ve mentioned earlier…

This is my Hangfire configuration in Program.cs file:

builder.Services.AddHangfire(configuration =\>  
{  
configuration  
.SetDataCompatibilityLevel(CompatibilityLevel.Version\_180)  
.UseSimpleAssemblyNameTypeSerializer()  
.UseRecommendedSerializerSettings()  
.UseSqlServerStorage(builder.Configuration.GetConnectionString(“HangfireConnection”));  
});
