I am hosting hangfire server inside Windows Service so that when my ps starts hangfire server starts automatically and start executing job.
Now the problem is when I host my Windows service in debug mode
as well as my shared library which contains code to execute long running jobs in debug mode
then everything is fine i.e hangfire is able to pick up and execute the job.
But when I host my Windows service as well as shared library in release mode then I get this below error:
Could not load file or assembly 'ClassLibrary1.SharedLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.
My Windows service is running on LocalSystem
and my database resides on colleague computer.
Code :
public partial class MyNewService1 : ServiceBase
{
private BackgroundJobServer _server;
private System.Diagnostics.EventLog eventLog1;
public MyNewService1()
{
InitializeComponent();
eventLog1 = new System.Diagnostics.EventLog();
if (!System.Diagnostics.EventLog.SourceExists("MySource"))
{
System.Diagnostics.EventLog.CreateEventSource(
"MySource", "MyNewLog");
}
eventLog1.Source = "MySource";
eventLog1.Log = "MyNewLog";
GlobalConfiguration.Configuration.UseSqlServerStorage("connectionstring");
}
protected override void OnStart(string[] args)
{
eventLog1.WriteEntry("In OnStart", EventLogEntryType.Information);
_server = new BackgroundJobServer();
}
protected override void OnStop()
{
_server.Dispose();
}
}
I have taken code from following reference: http://docs.hangfire.io/en/latest/background-processing/processing-jobs-in-windows-service.html
On docs nothing is mention like whether I should host Windows service in debug/release mode.
Is this a Windows service or hangfire problem?
Update : I think problem is related to Windows service as describe here but still no luck:
System.BadImageFormatException occurred when build in Release Mode