Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullReference Exception on Job Creation #15

Closed
PaulARoy opened this issue Apr 12, 2020 · 5 comments
Closed

NullReference Exception on Job Creation #15

PaulARoy opened this issue Apr 12, 2020 · 5 comments

Comments

@PaulARoy
Copy link

Hi,
I've just updated the nuget package and I experience a nullreference exception on job creation.

This really seems to be the possible NRE you talk about in fd5dc19

  • Could you provide an update to fix it?
  • Is there a possibility to workaround this?

Best regards,

@yongliu-mdsol
Copy link
Contributor

@PaulARoy

We encountered similar issue from our testing.
It seems to be the line below where BackgroundJob is null.
https://github.com/face-it/Hangfire.Tags/blob/master/src/Hangfire.Tags/States/CreateJobFilter.cs#L16

@erwin-faceit
Copy link
Contributor

The change @yongliu-mdsol suggested is added to release 1.5.1. I'm not sure, however, that it will fix your problem. It will merely throw another exception.

Let me now how things works out. If you're still having problems, please supply a snippet of code of initialization and usage (including used tags).

@PaulARoy
Copy link
Author

For me I think it just hid another exception (related to transaction scopes) — once I fixed the transaction scope issue I did not encounter this NRE again.

I'm not in need of an urgent fix.

Thanks for your awesome work!

@erwin-faceit
Copy link
Contributor

I'll close this for now, but I'm interested in why it gave you an exception in the first place. Perhaps you can share a piece of code?

@PaulARoy
Copy link
Author

Honnestly I don't really know why it happened, basically I was trying to launch the job inside a TransactionScope that had the wrong level of isolation (isolation level changed on 1.7 and I didn't know I had to update it).
That was throwing an exception inside the Hangfire library but it was then hidden by the Hangfire.Tag NRE.

A pretty messed up scenario, I highly doubt it would happen in a normal case.

The code could be summarized like:

SqlAzureConfiguration.SuspendExecutionStrategy = true; 
using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
{
    BackgroundJob.Enqueue<HangfireTaskHelper>(hth => hth.SomeMethodWithATagAnnotationAsync(null, someArgument));
}

Which was fixed by adding:

SqlAzureConfiguration.SuspendExecutionStrategy = true; 
using (var transaction = new TransactionScope(TransactionScopeOption.Required, 
                                              new TransactionOptions() { IsolationLevel = IsolationLevel.ReadCommitted }, 
                                              TransactionScopeAsyncFlowOption.Enabled))
{
    BackgroundJob.Enqueue<HangfireTaskHelper>(hth => hth.SomeMethodWithATagAnnotationAsync(null, someArgument));
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants