Maze90
Maze90

Reputation: 148

Exception when using Quartz with Topshelf

I am getting an error when trying to run Topshelf with Quartz

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()

My code is

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

I can't seem to find anything in relation to Quartz.Collection.Hashset with a google search and i'm unsure how to go about getting it if it is missing.

Upvotes: 1

Views: 814

Answers (2)

Curtis
Curtis

Reputation: 61

The NuGet package that you are using is outdated. I ran into the exact error and had to write my own integration. If you are using dtnuget package on NuGet you are definitely going to have this problem; that package was last updated in the year 2015. Your best bet is to use a NuGet package published by bertuko. I have used his implementation as the base of my own, and it works fine.

Upvotes: 0

Maze90
Maze90

Reputation: 148

I've put this down to the Quartz.Topshelf Nuget package not supporting .net core and had to resort to creating a windows service instead.

It appears you can do some very simple service creation with .net core 3.0 and above. So it renders Topshelf pretty much obselete. So this is defintely a better option.

Marking this as the answer unless this questions gets found by someone and they find a solution

Upvotes: 1

Related Questions