Quartz.net 的类型初始化程序抛出异常 [英] Type initializer for Quartz.net throws an exception

查看:56
本文介绍了Quartz.net 的类型初始化程序抛出异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究 Quartz.NET 2.0 beta 1.

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")));
    }
}

在使用 .Net 框架客户端配置文件进行多次失败测试后,我可以编译此代码...

I can compile this code after many failure tests with .Net framework Client Profile...

但是当它运行时,第一行的代码抛出:

But when it runs, code on first line throws:

'Quartz.Impl.StdSchedulerFactory' 的类型初始值设定项抛出一个例外.

The type initializer for 'Quartz.Impl.StdSchedulerFactory' threw an exception.

我找不到任何关于此的信息,有没有人有一些想法?

I can not find anything about this, has anyone got some ideas?

推荐答案

如果您使用 Copy local 将 Quartz 添加到您的项目中,请确保 Common.Logging.dll 与 Quartz 的程序集位于同一目录中.

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.

这篇关于Quartz.net 的类型初始化程序抛出异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆