【问题标题】:Type initializer for Quartz.net throws an exceptionQuartz.net 的类型初始化程序引发异常
【发布时间】:2011-12-27 16:27:37
【问题描述】:

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

我使用的是第一个示例代码,在我自己的项目中,我的代码是:

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 框架客户端配置文件进行多次失败测试后编译此代码...

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

“Quartz.Impl.StdSchedulerFactory”的类型初始化器抛出了一个 例外。

我找不到任何关于此的信息,有人有什么想法吗?

【问题讨论】:

  • 它是 Common Logging.dll,当我查看 InnerException 时,它说组件找不到所以我将它添加到我的项目中。

标签: c# quartz.net


【解决方案1】:

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

不确定这是否与客户端配置文件有关,但无论如何都要尝试使用完整的框架。

【讨论】:

  • 它是 Common Logging.dll,当我查看 InnerException 时,它说组件找不到所以我将它添加到我的项目中。
猜你喜欢
  • 1970-01-01
  • 2016-03-27
  • 1970-01-01
  • 1970-01-01
  • 2017-05-18
  • 2013-05-15
  • 2013-11-08
  • 2019-07-08
  • 2013-10-06
相关资源
最近更新 更多