Here’s the situation:
I’ve a Windows service (implementation by Topshelf) where I run the Hangfire server.
I’m using Autofac to resolve the jobtypes that are being processed. I register the types like this:
var asm = Assembly.Load(“Jobs”);
builder.RegisterAssemblyTypes(asm).Where(t => typeof(IJob).IsAssignableFrom(t)).AsImplementedInterfaces().AsSelf();
After building the container I do:
GlobalConfiguration.Configuration.UseActivator(new ContainerJobActivator(container));
The ContainerJobactivator does nothing other then resolve the jobtype from the container
Another application is the hangfire client and enueues the jobs like this:
BackgroundJob.Enqueue<T>
(x => x.Execute());
The T generic parameter always gets a class implementing IJob
after a few successfull tests I noticed that there seems to be a pattern emerging: (as I see in the dashboard)
1 The Job is created
2 the Job is enqueued
3 Failed. This happens a couple of times with:
System.TypeLoadException
Could not load type ‘Jobs.Job2’ from assembly ‘Jobs, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’.
System.TypeLoadException: Could not load type ‘Jobs.Job2’ from assembly ‘Jobs, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’.
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type)
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName)
at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)
at System.Type.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase)
at Hangfire.Storage.InvocationData.Deserialize()
But then:
after a step that says “Enqueued”“Triggered by DelayedJobScheduler”
The job gets processed without any problems.
Strange thing is:
The Job doesn’t hit a breakpoint in ContainerJobActivator until then. (untill it goes right that is…)
I’m using Hangfire 1.6.8 (on .Net4.5)
Autofac 4.3.0
Hope you can help!
Thanks.
Frans