我有一个运行 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();
}
}
}
但是现在当我尝试运行安装程序时出现错误:
Exception occurred while initializing the installation: System.BadImageFormatException: Could not load file or assembly 'file:///C:\Code \MyCode\Services\bin\Debug\MyService.exe' or one of its dependencies. A n attempt was made to load a program with an incorrect format..
是否有任何简单的方法来调试此消息?或者有人知道我可能错过了什么吗?
最佳答案
您如何运行安装?我敢打赌,您正在使用 64 位安装程序注册 32 位编译应用程序,反之亦然
换句话说,运行:
%windir%\Microsoft.NET\Framework\v4.0.30319\installutil.exe <My x64 DLL/EXE>
或:
%windir%\Microsoft.NET\Framework64\v4.0.30319\installutil.exe <My x86 DLL/EXE>
关于c# - 将控制台应用程序转换为 Windows 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24044529/