I have an unmanaged dll that I import into my c# console application:
[DllImport("mylib.dll", EntryPoint = "myfunction", CallingConvention = CallingConvention.Cdecl)]
public static extern void MyFunction();
The application works just fine.
Then, I use Topshelf to host my console app as a service:
var rc = HostFactory.Run(x =>
{
x.Service<StartupService>();
x.RunAsLocalSystem()
.StartAutomatically()
.EnableServiceRecovery(r =>
{
r.RestartService(0);
r.SetResetPeriod(1);
});
x.SetStartTimeout(TimeSpan.FromSeconds(120));
x.SetStopTimeout(TimeSpan.FromSeconds(120));
x.SetDescription("my service");
x.SetDisplayName("service");
x.SetServiceName("service");
});
I install and start the service like so:
myapp.exe install
myapp.exe start
The service starts, but an error appear in logs saying it can't find my dll:
System.DllNotFoundException: Unable to load DLL 'mylib.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
Update: I tried passing a full path and even putting it into System32. Still does not work.
Thanks!
User contributions licensed under CC BY-SA 3.0