I am creating an MSI package for installing and starting Windows services using WiX v3.8. The code as follows:
The error message you are getting is the generic message the Windows Installer sends when it fails to start a service during install. Almost always the issue is that the Service is missing a dependency or otherwise not fully configured when the start occurs. To debug the root issue try:
If this is a service written in managed code, ensure that it does not depend on files being placed in the GAC. Files are not in the GAC until very, very late during the installation process. If you must use files in the GAC, you will not be able to use the built-in ServiceControl
element and will have to write a custom action to run after InstallFinalize
. Note that after InstallFinalize
a custom action will not be elevated so your service will have to support being started by non-elevated users. Again, I recommend not depending on the GAC.
Good luck debugging your service!
When debugging a service startup issue, I always just use a simple if() statement that checks for the existence of a particular file in the installation directory. When the service fails, I open a command prompt (before dismissing the dialog indicating the failure) and use "echo >thatfile" to create the file that I am looking for in the if(). The object of the if() is the Debugger.Launch() invocation.
Now, I can dismiss the dialog and rerun the installer and this time it will start the debugger and I can see what happens. I tend to use static class init as the moment to launch the debugger, but you can try to do it in "OnStart()", but if there are loading/binding issues, you probably won't get to that point before it dies. Whereas doing it during static class init will almost always tell you the things that you need to address as dependencies.
So I got this error today because my service had dependencies that had to be GACed before starting the service. As it turns out, dependencies are GACed last by the installer, and there's really no good way to get around this without building some kind of bootstraper/multipart installer.
However, I found the following resolution: deploy the assemblies both to the GAC and install them in the same directory as the service. This way, the service will be able to find the DLLs on start in the program files directory, and they will be GACed (which was a requirement for other reasons).
To do this, I had to create two separate component groups, and a "dummy" Directory:
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLDIR" Name="NameOfProgram" />
<Directory Id="GacDlls" Name="libs" />
</Directory>
</Directory>
I then create two Component Groups: one that has the exe and all libraries, and a second with the same libraries with the Assembly attribute set to ".net":
<ComponentGroup Id="ServiceLibs" Directory="GACDlls">
<Component Id="log4netGAC"
Guid="a23099ac-5880-4b6e-af3f-fa7cef113226">
<File Id="log4net.dllGAC"
Name="log4net.dll"
Source="..\ProjectDir\bin\$(var.Configuration)\log4net.dll"
KeyPath="yes"
Vital="yes"
DiskId="1"
Assembly=".net"
/>
</Component>
</ComponentGroup>
<ComponentGroup Id="ProductComponents" Directory="INSTALLDIR">
<Component Id="log4net"
Guid="463e05db-e248-44d7-bbde-467358b7310f">
<!-- normally we'd want to GAC this (Assembly=".net"), but that would prevent us from starting the service up during install so we'll just drop it in the program folder -->
<File Id="log4net.dll"
Name="log4net.dll"
Source="..\ProjectName\bin\$(var.Configuration)\log4net.dll"
KeyPath="yes"
Vital="yes"
DiskId="1"
/>
</Component>
... other components ...
</ComponentGroup>
And now it works!
The ServiceInstall Account is obfuscated in the OP's example, but this error can happen if one forgets to fully qualify the account, as such:
<ServiceInstall ... Account="NT AUTHORITY\LocalService" />
Your installer will fail if you only specify the username (w/o the NT Authority) like this:
<ServiceInstall ... Account="LocalService" />
Remember to add "Log on as a service" rights to the [SERVICEACCOUNT],
To add the "Log on as a service" right to an account on your local computer
1) Open Local Security Policy.
2) In the console tree, double-click Local Policies, and then click User Rights Assignments.
3) In the details pane, double-click Log on as a service.
4) Click Add User or Group, and then add the appropriate account to the list of accounts that possess the Log on as a service right.
From: http://technet.microsoft.com/en-us/library/cc739424%28v=ws.10%29.aspx.