我有一个使用SignalR的控制台应用程序。现在我想将其转换为Windows服务应用程序。
我只需将
并添加了一个服务类,它很简单:
但是,现在当我尝试运行安装程序时,出现以下错误信息:
我只需将
Main
方法替换为:static void Main()
{
var servicesToRun = new ServiceBase[]
{
new MyService()
};
ServiceBase.Run(servicesToRun);
}
并添加了一个服务类,它很简单:
namespace Services
{
partial class MyService : ServiceBase
{
IDisposable SignalR { get; set; }
public MyService()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
const string url = "https://localhost:8080";
using (SignalR = WebApp.Start<Startup>(url))
{
//TODO: Add Logging
}
}
protected override void OnStop()
{
SignalR.Dispose();
}
}
}
但是,现在当我尝试运行安装程序时,出现以下错误信息:
是否有简单的方法来调试此消息?还是有人知道我可能错过了什么?初始化安装程序时发生异常: System.BadImageFormatException: 无法加载文件或程序集 'file:///C:\Code \MyCode\Services\bin\Debug\MyService.exe' 或 其中一个依赖项。 尝试使用不正确格式的程序加载程序。