We left Russia. We are against aggression and war with Ukraine. It is a tragedy for our nations, it is a nightmare

Could use a little help updating Hangfire to work with Unity 5.11

I’m in the process of trying to update a bunch of NuGet packages in my solution and I’ve been avoiding updating Unity for a while. I’m close to having it updated to 5.x but I’m having trouble getting it to work with Hangfire.

My code looks like this:

var container = new Unity.UnityContainer();
GlobalConfiguration.Configuration.UseUnityActivator(container);  <-- line 52

I’m getting this error:

Severity Code Description Project File Line Suppression State
Error CS0012 The type ‘IUnityContainer’ is defined in an assembly that is not referenced. You must add a reference to assembly ‘Unity.Abstractions, Version=, Culture=neutral, PublicKeyToken=6d32ff45e0ccc69f’. MyProj C:*****\App_Start\HangFireConfig.cs 52 Active

I suspect it’s some kind of version dependency either artificial (meaning it would work if the explicit requirement was not specified) or real (meaning the code needs to change before it supports it).

package versions:
Hangfire.Unity 3.0.0
Unity 5.11.2
Unity.Abstractions 5.11.2
Unity.Container 5.11.4
Unity.Mvc 5.11.1
Unity.Mvc5 v1.4.0
Unity.Web.API 5.4.0

Any help would be greatly appreciated.

So I’m pretty sure this is because they lost the signing certificate for Unity and created a new one and that’s what version 5 is–version 4 with a different signing certificate.

This is backed up by the description of version 5 under the roadmap at:

So Hangfire.Unity wants an assembly with the old publickKeyToken (6d32ff45e0ccc69f) and the publicKeyToken is now 489b6accfaf20ef0

I guess there needs to be a Hangfire.Unity V5 now???

I worked around the issue by creating my own Unity job activator:

    public class UnityJobActivator : JobActivator
    private IUnityContainer _container;

    public UnityJobActivator(IUnityContainer container)
        _container = container;

    public override object ActivateJob(Type type)
        return _container.Resolve(type);

And then configured it for Hangfire:

GlobalConfiguration.Configuration.UseActivator(new UnityJobActivator(container));

and removed all Hangfire.Unity* NuGet packages.

(tried to edit solution post but site wouldn’t let me)