Question

I just took over a bunch of C# code from another company, and I'm having big trouble getting the first build to work. The issue seems to be some Lambda syntax used by a framework called "Topshelf". I apollogise if this is basic knowledge, but i'm rather new to Microsoft programming, and have no idea how to resolve this issue.

The problem is boiled down to a single static class, handling all the services in the application.

This is the Topshelf Documentation for how it should be configured: http://docs.topshelf-project.com/en/latest/configuration/quickstart.html

And this is the code for how it's actualle configured (Some of it, but it should provide the picture):

  public static void Main (string[] args)
            {

                    XmlConfigurator.Configure ();
                    HostFactory.Run (
                    x => 
                    {
                            x.Service<InvoiceGenerator>(
                                s => {
                                    s.SetServiceName("NAME");
                                    s.ConstructUsing(name => new InvoiceGenerator());
                                    s.WhenStarted(ser => ser.Start());
                                    s.WhenStopped(ser => ser.Stop());
                                }
                            );


            }
       }
 }

But when done like this, Visual studio complains about every line of code. Among the errors are:

Delegate 'System.Func<Tools.Services.InvoiceGenerator>' does not take 1 arguments

Not all code paths return a value in lambda expression of type 'System.Func<Tools.Services.InvoiceGenerator>'

I am 100 % certain, that this is some kind of interpretation issue from Visual Studio's side, since the code is live atm. I just can't build it in VS.

Do any of you have any idea what I am missing, or doing wrong? Remember; the code is working and live atm.

Thank you in advance.

Was it helpful?

Solution

It looks like this code was built on an older version of Topshelf (1.x, maybe 2.x). Using those binaries will likely fix your problem. Multiple hosted services are not supported under the 3.x version of Topshelf.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top