I’m trying to execute a Quartz.net job from a separate assembly. The class inherits from the IJob interface, implements the Execute method, and has been copied into the same folder as Quartz.Server.exe, but I’m getting the following error:
Error scheduling jobs: Could not load file or
assembly 'TestJobs' or one of its dependencies. An attempt was made to load a p
rogram with an incorrect format.
System.BadImageFormatException: Could not load file or assembly 'TestJobs' or on
e of its dependencies. An attempt was made to load a program with an incorrect format.
File name: 'TestJobs'
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError,
Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, Bool
ean loadTypeFromPartialName, ObjectHandleOnStack type)
... (snipped)
I’m using version 2 beta 2. The server application has been unzipped into a separate folder and is being executed by running Quartz.Server.exe at the command line.
My sample job is a separate assembly named TestsJobs with a very basic job to write to a text file:
public class TestJob : IJob
{
public void Execute(IJobExecutionContext context)
{
try
{
string path = @"c:\test.txt";
while (true)
{
var line = DateTime.Now.ToString() + " - " + Guid.NewGuid();
File.AppendAllText(path, line);
Thread.Sleep(500);
}
catch (Exception ex)
{
throw new JobExecutionException("Error", ex, false);
}
}
}
}
This is a basic class library project targeting .NET 4. It is copied into the Quartz.Net server folder where Quartz.Server.exe is being run from.
The quartz_jobs.xml file has the job set using the default file, with just the job type changed to reflect the new assembly and class:
<job-type>TestJobs.TestJob, TestJobs</job-type>
Thought this might be something to do with framework versioning, but Quartz.net seems to be using .NET 4 as well (Quartz.dll has dependencies on v4 assemblies).
There’s another question on SO about the same type of issue, but it doesn’t have a clear answer.
Is there anything else I need to do so that the job can be loaded and executed?
The solution to this turned out to be a bit simpler that I thought. It was caused by my assembly with the test job being compiled for x86 instead of AnyCPU (or x64) and using Windows 7 x64.