C# Topshelf框架错误
我刚从另一家公司接手了一堆C代码,而我在第一次构建工作中遇到了很大的困难。问题似乎是一个名为“Topshelf”的框架使用的Lambda语法。我想知道这是否是基础知识,但我对微软编程相当陌生,不知道如何解决这个问题C# Topshelf框架错误,c#,.net,lambda,topshelf,C#,.net,Lambda,Topshelf,我刚从另一家公司接手了一堆C代码,而我在第一次构建工作中遇到了很大的困难。问题似乎是一个名为“Topshelf”的框架使用的Lambda语法。我想知道这是否是基础知识,但我对微软编程相当陌生,不知道如何解决这个问题 public static void Main (string[] args) { XmlConfigurator.Configure (); HostFactory.Run
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());
}
);
}
}
}
问题归结为一个静态类,处理应用程序中的所有服务
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());
}
);
}
}
}
以下是Topshelf文档,介绍了如何配置:
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());
}
);
}
}
}
这是如何实际配置的代码(其中一些,但应该提供图片):
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());
}
);
}
}
}
publicstaticvoidmain(字符串[]args)
{
Configure();
霍斯特工厂,快跑(
x=>
{
x、 服务(
s=>{
s、 SetServiceName(“名称”);
s、 ConstructUsing(name=>newinvoicegenerator());
s、 开始时(ser=>ser.Start());
s、 停止时(ser=>ser.Stop());
}
);
}
}
}
但这样做时,Visual studio会抱怨每一行代码。错误包括:
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());
}
);
}
}
}
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>'
委托“System.Func”不接受1个参数
并非所有代码路径都在lambda表达式中返回“System.Func”类型的值
我100%确定,这是Visual Studio方面的某种解释问题,因为代码是实时atm。我只是无法在VS中构建它
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());
}
);
}
}
}
你们有谁知道我遗漏了什么或做错了什么吗?记住,代码是有效的
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());
}
);
}
}
}
提前感谢。这段代码似乎是在较旧版本的Topshelf(1.x,可能是2.x)上构建的。使用这些二进制文件可能会解决您的问题。3.x版本的Topshelf不支持多个托管服务。这段代码似乎是在较旧版本的Topshelf(1.x,可能是2.x)上构建的。使用这些二进制文件可能会解决您的问题。3.x版本的Topshelf不支持多个托管服务。这里是一个关于acutal错误的链接:这里是一个关于acutal错误的链接:非常感谢!它非常有效。(虽然,从我在文档中看到的来看,只有3.x不支持多个服务)。非常感谢!它工作起来很有魅力。(虽然,从我在文档中看到的来看,只有3.x不支持多个服务)。
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());
}
);
}
}
}