Hangfire 1.6.0 beta2 is not allowing for adding JobFilterAttributes

Created on 4 May 2016  路  4Comments  路  Source: HangfireIO/Hangfire

Hi,

We are using Hangfire 1.6.0 beta2 for a new feature created by this pull
https://github.com/HangfireIO/Hangfire/pull/523

but we faced an issue adding a JobFilterAttribute to GlobalJobFilters.Filters when executing any job, it will fire null reference exception.

After some investigation in latest source code in dev branch we realized that the root cause of this issue is this line in GlobalJobFilters.cs

static GlobalJobFilters()
        {
            Filters = new JobFilterCollection
            {
                new CaptureCultureAttribute(),
                new AutomaticRetryAttribute(),
                new StatisticsHistoryAttribute(),
                new ContinuationsSupportAttribute()
            };
        }

It seems that the collection initializer is setting JobFilterProviders.Providers -> first element in list = null

By reverting this initialization to old way, issue fixed

static GlobalJobFilters()
        {
            Filters = new JobFilterCollection();
            Filters.Add(new CaptureCultureAttribute());
            Filters.Add(new AutomaticRetryAttribute());
            Filters.Add(new StatisticsHistoryAttribute());
            Filters.Add(new ContinuationsSupportAttribute());
        }

We rolled back to beta1 which doesn't have this issue till you have the chance to fix it.

Attached same MVC sample (startup.cs file) in dev branch with adding a simple JobFilterAttribute to show you the issue.

startup.cs.txt

bug

All 4 comments

Just confirming I ran into this same issue with GlobalJobFilters.Filters on 1.6.0 beta2 when using the following. Thanks @abdelrady for tracking down the change. Was caused by using the following.

GlobalJobFilters.Filters.Add(new AutomaticRetryAttribute { Attempts = 3 });

Guys, thanks for reporting and investigating this :heart: It is awesome when a bug is reported during the beta. The fix is available in the CI Feed in version 1.6.0-build-02018.

Thanks @odinserj for the quick fix, do you have any plans to release this to NuGet packages soon ?

I'm planning to release it with beta3, next week or so. Currently you can use the CI feed to obtain the fix

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nathvi picture nathvi  路  4Comments

cbmek picture cbmek  路  3Comments

shorbachuk picture shorbachuk  路  4Comments

odinserj picture odinserj  路  4Comments

jeffsugden picture jeffsugden  路  4Comments