【发布时间】:2020-03-16 04:20:39
【问题描述】:
尝试使用 Quartz 运行 Topshelf 时出现错误
Topshelf.Hosts.ConsoleRunHost Error: 0 : An exception occurred, System.TypeLoadException: Could not load type
'Quartz.Collection.HashSet`1' from assembly 'Quartz, Version=3.0.7.0, Culture=neutral, PublicKeyToken=*'.
at Topshelf.Quartz.ScheduleJobServiceConfiguratorExtensions.<>c__DisplayClassa`1.<ConfigureJob>b__3()
at Topshelf.Runtime.EventCallbackList`1.Notify(T data)
at Topshelf.Builders.DelegateServiceBuilder`1.DelegateServiceHandle.Start(HostControl hostControl)
at Topshelf.Hosts.ConsoleRunHost.Run()
我的代码是
HostFactory.Run(x =>
{
x.Service<Service>(s =>
{
s.WhenStarted(service => service.Start());
s.WhenStopped(service => service.Stop());
s.ConstructUsing(() => new Service());
s.ScheduleQuartzJob(q =>
q.WithJob(() =>
JobBuilder.Create<Notifications>().Build())
.AddTrigger(() => TriggerBuilder.Create()
.WithSimpleSchedule(b => b.WithIntervalInSeconds(10)
.RepeatForever())
.Build()));
});
x.RunAsLocalSystem()
.StartAutomatically();
x.SetDescription("Quartz Service");
x.SetDisplayName("QuartzService");
x.SetServiceName("QuartzService");
});
我似乎无法通过谷歌搜索找到与 Quartz.Collection.Hashset 相关的任何内容,如果它丢失,我不确定如何获取它。
【问题讨论】:
-
能否检查一下程序集Quartz, Version=3.0.7.0是否在可执行文件所在的目录下?
-
我实际上无法在我的项目文件中找到 .exe。有没有我遗漏的步骤?
-
在您的项目文件所在的文件夹中有一个子文件夹 bin\debug 。这是您的解决方案中已编译的 exe 和 dll 文件所在的位置。根据您的解决方案的结构,您的程序集的依赖关系可能不会在那里被复制。所以第一步是查看 Quartz dll 是否位于
\bin\debug. -
看一下,里面没有 Topshelf 或 Quartz 特定的 DLL。只是我的项目 DLL。
-
试试这个:在 VS 中,转到引用 Quartz 和 Topshelf 的项目。在解决方案资源管理器中选择引用,选择属性选项卡并设置“CopyLocal”=“True”。如果这不能解决您的问题,请查看此帖子:stackoverflow.com/questions/602765/…
标签: c# assemblies quartz.net quartz topshelf