问题
I'm taking a look at Quartz.NET 2.0 beta 1.
I'm using the first example code, in my own project, my code is:
class Program
{
static void Main(string[] args)
{
// First we must get a reference to a scheduler
ISchedulerFactory sf = new StdSchedulerFactory();
IScheduler sched = sf.GetScheduler();
// computer a time that is on the next round minute
DateTimeOffset runTime = DateBuilder.EvenMinuteDate(DateTimeOffset.UtcNow);
// define the job and tie it to our HelloJob class
IJobDetail job = JobBuilder.Create<HelloJob>()
.WithIdentity("job1", "group1")
.Build();
// Trigger the job to run on the next round minute
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity("trigger1", "group1")
.StartAt(runTime)
.Build();
// Tell quartz to schedule the job using our trigger
sched.ScheduleJob(job, trigger);
Console.WriteLine(string.Format("{0} will run at: {1}", job.Key, runTime.ToString("r")));
// Start up the scheduler (nothing can actually run until the
// scheduler has been started)
sched.Start();
// wait long enough so that the scheduler as an opportunity to run the job!
// wait 65 seconds to show jobs
Thread.Sleep(TimeSpan.FromSeconds(65));
// shut down the scheduler
sched.Shutdown(true);
}
}
/// <summary>
/// This is just a simple job that says "Hello" to the world.
/// </summary>
/// <author>Bill Kratzer</author>
/// <author>Marko Lahma (.NET)</author>
public class HelloJob : IJob
{
/// <summary>
/// Empty constructor for job initilization
/// <para>
/// Quartz requires a public empty constructor so that the
/// scheduler can instantiate the class whenever it needs.
/// </para>
/// </summary>
public HelloJob()
{
}
/// <summary>
/// Called by the <see cref="IScheduler" /> when a
/// <see cref="ITrigger" /> fires that is associated with
/// the <see cref="IJob" />.
/// </summary>
public virtual void Execute(IJobExecutionContext context)
{
// Say Hello to the World and display the date/time
Console.WriteLine(string.Format("Hello World! - {0}", System.DateTime.Now.ToString("r")));
}
}
I can compile this code after many failure tests with .Net framework Client Profile...
But when it runs, code on first line throws:
The type initializer for 'Quartz.Impl.StdSchedulerFactory' threw an exception.
I can not find anything about this, has anyone got some ideas?
回答1:
If you added Quartz to your project with Copy local, make sure that Common.Logging.dll is present in the same directory as Quartz's assembly.
Not sure if this has anything to do with client profile, but try it anyway with full framework.
来源:https://stackoverflow.com/questions/8639085/type-initializer-for-quartz-net-throws-an-exception