Reputation: 791
I would like to create a setup for my windows service. The dlls of my windows service are placed in /Lib/ folder.
I added an installer class to the service. And added a custom action on the setup project.
The problem is that when I try to install the service - it fails with the error: Error 1001. Unable to get installer types in ...
This error happens because the dlls are not in the same directory as the service .exe. I am using probing in the service config and install util doesn't recognize that probing..
I wanted to find a work around for that problem and tryed in many ways to create the service using service controller(sc.exe). Trying to run it as a custom action using cmd.exe. Etc..
This should be a common problem..did anybody find a proper solution for that?
Upvotes: 6
Views: 1639
Reputation: 8084
I've had the same problem, and none of the options suggested in this post or MSDN helped. I figured another solution:
By using Reflector on InstallUtil.exe, I discovered that InstallUtil is merely a thin wrapper for calling System.Configuration.Install.ManagedInstallerClass.InstallHelper(args)
inside a try/catch block (it also sets the current thread's UI culture and displays the copyright). ManagedInstallerClass.InstallHelper
itself resides in the System.Configuration.Install.dll assembly, accessible to everyone.
Thus, I simply modified the Program.Main
method of my service to allow installation. See the quick-and-dirty code below:
static class Program
{
static void Main(string[] args)
{
if (args != null && args.Any(arg => arg == "/i" || arg == "/u"))
{
// Install or Uninstall the service (mimic InstallUtil.exe)
System.Configuration.Install.ManagedInstallerClass.InstallHelper(args);
}
else
{
// Run the service
System.ServiceProcess.ServiceBase[] ServicesToRun;
ServicesToRun = new System.ServiceProcess.ServiceBase[]
{
new MyService()
};
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
}
}
}
You can do the same, or create your own version of InstallUtil.
Upvotes: 2
Reputation: 8233
in your config you can add probing path - it's a hint to the runtime where to look for an assembly http://msdn.microsoft.com/en-us/library/823z9h8w%28v=vs.80%29.aspx
Upvotes: 0
Reputation: 13986
You should bind to the AppDomain.AssemblyResolve
event and do your custom loading in the event handler.
A sample can be found in the first answer to this SO question.
Upvotes: 0