0

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.

Maze90
  • 108
  • 16
  • 1
    Can you check if the assembly Quartz, Version=3.0.7.0 is in the directory in which the executable is located? – StefanFFM Nov 20 '19 at 13:09
  • I can't actually find the .exe in my project files. Is there a step i'm missing? – Maze90 Nov 20 '19 at 13:33
  • In the folder where your project file is located there is a subfolder bin\debug . This is where the compiled exe and dll files from your solution are located. Depending on how your solution is structured it maybe that the depedencies of your assemblies will not get copied there. So there first step is to see if the Quartz dll is located in \bin\debug. – StefanFFM Nov 20 '19 at 13:47
  • Looking at it, none of the Topshelf or Quartz specific DLLs are in there. Just my project DLLs. – Maze90 Nov 20 '19 at 13:53
  • Try this: In VS, go to your project that references Quartz and Topshelf. In the solution explorer select the reference, select the properties tab and set "CopyLocal" = "True". If that does not solve your problem, take a look at this post: https://stackoverflow.com/questions/602765/when-should-copy-local-be-set-to-true-and-when-should-it-not – StefanFFM Nov 20 '19 at 14:15
  • None of my referenced projects have Quartz of Topshelf, it's installed on the correct project but the nuget packages are saved in a different location to the project itself – Maze90 Nov 21 '19 at 09:10

2 Answers2

1

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

Maze90
  • 108
  • 16
0

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.

Curtis
  • 51
  • 1
  • 4