Quartz.Net Initializing Project

浪尽此生 提交于 2019-12-05 13:18:50

After downloading project and following step-by-step tutorial, I found problem with it, after a some time spent in debugger. So tutorial will guide you from client side perspective on using Quartz.NET, and there are no problems with it. Code is building fine, and everything works like a charm. Problem is on server side of project, and error you are getting is sent from service that is running Quartz.NET server implementation. Line throwing an exception is:

// Line 40 | ScheduleJob.cs
var schedule = schd.ScheduleJob(job, trigger);

What's happening here is that scheduler is informed about new job called WriteHelloToConsole for HelloWorldJob class implementing IJob interface. Once server receives this information, he tries to find that dll within his application domain (here comes problem). However, there are no HelloWorldJob in Quartz.NET server domain (folder), since you have downloaded it directly from the SourceForge server. That is reason why you are getting could not load file or assembly.

Solution is simple, yet not recommended, but for this tutorial sufficient. You just need to copy/paste HelloWorldQuartzDotNet.exe into the Quart.NET service folder and start/stop service from Windows Services. Once you do this, it will load HelloWorldJob class (and also other classes from HelloWorldQuartzDotNet.exe) in Quartz.NET server application domain.

Recommended solution for other project, specially for production. Create separate DLL for each of your, so one DLL for IJob class and separate DLL for Quartz.NET. Add references to the client and copy/paste DLLs to service. This way you will have everything decoupled and you will get maintainable solution.

If you need more about how .NET application domain works, you can get it from this link.


Note: Best way to start/learn/play with Quartz .NET is with their documentation. There is a handy tutorial on how to setup everything from small console app to the windows service. I have implemented it several times, only using documentation.

Quartz.NET

I'm willing to help for any particular question.

Mscorlib.dll is a class library which contains core functions of the .NET framework and it is clearly letting you know that it cannot find HelloWorldDotNet assembly by throwing FileNotFoundException...

Make sure that your HelloWorldDotNet assembly builds fine. Check what is your StartUp project in Visual Studio and make sure it is correct and has a reference to this assembly. Check all the references in your project...

Check solution properties. Have you checked optimize code checkbox there? Try unchecking it and then compile and run.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!