# .Net Core Error on BackgroundJob.Enqueue

**URL:** <https://discuss.hangfire.io/t/net-core-error-on-backgroundjob-enqueue/3144>\
**Category:** bug?\
**Tags:** sql-server, aspnetcore, dotnetcore\
**Created:** [March 31, 2017, 9:11pm UTC](https://discuss.hangfire.io/t/net-core-error-on-backgroundjob-enqueue/3144 "2017-03-31T21:11:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dynamiclynk](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/dynamiclynk/32/920_2.png) [@dynamiclynk](https://discuss.hangfire.io/u/dynamiclynk)\
**Post date:** [March 31, 2017, 9:11pm UTC](https://discuss.hangfire.io/t/net-core-error-on-backgroundjob-enqueue/3144/1 "2017-03-31T21:11:20Z")

</div>

So when I execute BackgroundJob.Enqueue I get the following Exception for version 1.6.12.

> JobStorage.Current property value has not been initialized

My ConfigureServices is as follows my Server is running fine in a standalone Winform app.

`services.AddHangfire(v => v.UseSqlServerStorage(configFile.Root.GetConnectionString("HangfireDB")));`

If I wire it up as below it seems to work, am I configuring the client incorrectly to receive this error?

```
services.AddHangfire(configuration => { });
JobStorage.Current = new SqlServerStorage(configFile.Root.GetConnectionString("HangfireDB"));

```

**Winform Hangfire Server**

 ![](https://europe1.discourse-cdn.com/flex017/uploads/hangfire/original/1X/5fc7a353d6004e2c217d657d682fea44bb8fc41f.png)

---

<div class="post-metadata">

**Author:** ![pieceofsummer](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/pieceofsummer/32/785_2.png) [@pieceofsummer](https://discuss.hangfire.io/u/pieceofsummer)\
**Post date:** [March 31, 2017, 10:05pm UTC](https://discuss.hangfire.io/t/net-core-error-on-backgroundjob-enqueue/3144/2 "2017-03-31T22:05:11Z")

</div>

Configuration block is not called in client-only scenarios unless you inject the related service somewhere. You should either explicitly initialize `JobStorage.Current` (as you did), or use `IBackgroundJobClient` service instead of static methods (preferred).

---

<div class="post-metadata">

**Author:** ![dynamiclynk](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/dynamiclynk/32/920_2.png) [@dynamiclynk](https://discuss.hangfire.io/u/dynamiclynk)\
**Post date:** [March 31, 2017, 10:41pm UTC](https://discuss.hangfire.io/t/net-core-error-on-backgroundjob-enqueue/3144/3 "2017-03-31T22:41:52Z")

</div>

Thanks I went with injecting the **IBackgroundJobClient** and just getting the IBackgroundJobClient instance via the MVC Controller constructor. Works perfect.

```
 services.AddTransient<IBackgroundJobClient>(provider => new BackgroundJobClient(new
                    SqlServerStorage(configFile.Root.GetConnectionString("HangfireDB"))));
```

---

<div class="post-metadata">

**Author:** ![pieceofsummer](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/pieceofsummer/32/785_2.png) [@pieceofsummer](https://discuss.hangfire.io/u/pieceofsummer)\
**Post date:** [March 31, 2017, 10:43pm UTC](https://discuss.hangfire.io/t/net-core-error-on-backgroundjob-enqueue/3144/4 "2017-03-31T22:43:50Z")

</div>

You don’t even need to add it to service container, as `AddHangfire()` does it for you.

---

<div class="post-metadata">

**Author:** ![dynamiclynk](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/dynamiclynk/32/920_2.png) [@dynamiclynk](https://discuss.hangfire.io/u/dynamiclynk)\
**Post date:** [March 31, 2017, 10:54pm UTC](https://discuss.hangfire.io/t/net-core-error-on-backgroundjob-enqueue/3144/5 "2017-03-31T22:54:54Z")

</div>

Winner winner. 😄 Thanks! I did as you suggested and was able to get the IBackgroundJobClient service from the Controller.

**Add this to ConfigureServices**

```
 services.AddHangfire(configuration =>
                {
                    configuration.UseSqlServerStorage(configFile.Root.GetConnectionString("HangfireDB"));
                });

```

**Add this to the MVC Controller**  
`public MyController(IBackgroundJobClient jobClient)`
