Windows Service Installation

I’ve created an essentially empty windows service to test in an Octopus deployment. After a couple false starts (packing the MSI from an installer project instead of the output from the windows service project) I ended up getting the service to install to a Windows 7 machine, but it fails to install on Win2008R2.

The Failing Installation:

2011-07-08 19:35:34 INFO   Deploying release '1.0.2' of project 'AwesomeService' into environment 'Development'
2011-07-08 19:35:34 INFO   Downloading NuGet package AwesomeService 1.0.2 from feed: '\\d1515b-cmcbride\Files'
2011-07-08 19:35:34 DEBUG  Completed download of NuGet package AwesomeService 1.0.2
2011-07-08 19:35:34 DEBUG  Uploading package AwesomeService 1.0.2 to tentacle http://KUCY2DAPPFAB01:10933
2011-07-08 19:35:35 DEBUG  Package AwesomeService 1.0.2 has already been uploaded to tentacle 'http://KUCY2DAPPFAB01:10933', no need to upload it
2011-07-08 19:35:35 DEBUG  Deploying package AwesomeService 1.0.2 to tentacle http://KUCY2DAPPFAB01:10933
2011-07-08 19:35:36 INFO   Deployment successful. Tentacle output follows:
2011-07-08 19:35:35 DEBUG  Tasks will be run in the following order: 
 - PowerShellPreDeployScript
 - XmlConfigTransforms
 - XmlConfigVariables
 - PowerShellDeployScript
 - Installers
 - IisWebSite
 - PowerShellPostDeployScript
2011-07-08 19:35:35 INFO   Updating any .config files
2011-07-08 19:35:35 INFO   Installing any Installers
2011-07-08 19:35:35 DEBUG  Scanning assembly: C:\Octopus\Tentacle\Applications\AwesomeService.1.0.2\content\AwesomeService.exe
2011-07-08 19:35:35 DEBUG  Running InstallUtil  /i "C:\Octopus\Tentacle\Applications\AwesomeService.1.0.2\content\AwesomeService.exe"  /OctopusEnvironmentName="Development"
2011-07-08 19:35:35 DEBUG  InstallUtil 'C:\Octopus\Tentacle\Applications\AwesomeService.1.0.2\content\AwesomeService.exe' completed.
2011-07-08 19:35:35 DEBUG  InstallUtil output:
2011-07-08 19:35:35 DEBUG  Microsoft (R) .NET Framework Installation utility Version 4.0.30319.1
Copyright (c) Microsoft Corporation.  All rights reserved.

Exception occurred while initializing the installation:
System.BadImageFormatException: Could not load file or assembly 'file:///C:\Octopus\Tentacle\Applications\AwesomeService.1.0.2\content\AwesomeService.exe' or one of its dependencies. An attempt was made to load a program with an incorrect format..

2011-07-08 19:35:35 DEBUG  A web.config file was not found, so no IIS configuration will be performed.
2011-07-08 19:35:35 INFO   Deployment complete!

The Same Service/Package Installing Successfully:

2011-07-08 19:31:25 INFO   Deploying release '1.0.2' of project 'AwesomeService' into environment 'Development'
2011-07-08 19:31:25 INFO   Downloading NuGet package AwesomeService 1.0.2 from feed: '\\XXX\Files'
2011-07-08 19:31:25 DEBUG  Completed download of NuGet package AwesomeService 1.0.2
2011-07-08 19:31:25 DEBUG  Uploading package AwesomeService 1.0.2 to tentacle http://XXX:10933
2011-07-08 19:31:26 DEBUG  Package AwesomeService 1.0.2 has already been uploaded to tentacle 'http://XXX:10933', no need to upload it
2011-07-08 19:31:26 DEBUG  Deploying package AwesomeService 1.0.2 to tentacle http://XXX:10933
2011-07-08 19:31:29 INFO   Deployment successful. Tentacle output follows:
2011-07-08 19:31:26 DEBUG  Tasks will be run in the following order: 
 - PowerShellPreDeployScript
 - XmlConfigTransforms
 - XmlConfigVariables
 - PowerShellDeployScript
 - Installers
 - IisWebSite
 - PowerShellPostDeployScript
2011-07-08 19:31:26 INFO   Updating any .config files
2011-07-08 19:31:26 INFO   Installing any Installers
2011-07-08 19:31:26 DEBUG  Scanning assembly: C:\Octopus\Tentacle\Applications\AwesomeService.1.0.2\content\AwesomeService.exe
2011-07-08 19:31:26 DEBUG  Running InstallUtil  /i "C:\Octopus\Tentacle\Applications\AwesomeService.1.0.2\content\AwesomeService.exe"  /OctopusEnvironmentName="Development"
2011-07-08 19:31:28 DEBUG  InstallUtil 'C:\Octopus\Tentacle\Applications\AwesomeService.1.0.2\content\AwesomeService.exe' completed.
2011-07-08 19:31:28 DEBUG  InstallUtil output:
2011-07-08 19:31:28 DEBUG  Microsoft (R) .NET Framework Installation utility Version 4.0.30319.1
Copyright (c) Microsoft Corporation.  All rights reserved.


Running a transacted installation.

Beginning the Install phase of the installation.
See the contents of the log file for the C:\Octopus\Tentacle\Applications\AwesomeService.1.0.2\content\AwesomeService.exe assembly's progress.
The file is located at C:\Octopus\Tentacle\Applications\AwesomeService.1.0.2\content\AwesomeService.InstallLog.
Installing assembly 'C:\Octopus\Tentacle\Applications\AwesomeService.1.0.2\content\AwesomeService.exe'.
Affected parameters are:
   logtoconsole = 
   i = 
   logfile = C:\Octopus\Tentacle\Applications\AwesomeService.1.0.2\content\AwesomeService.InstallLog
   assemblypath = C:\Octopus\Tentacle\Applications\AwesomeService.1.0.2\content\AwesomeService.exe
Installing service AwesomeService...
Service AwesomeService has been successfully installed.
Creating EventLog source AwesomeService in log Application...

The Install phase completed successfully, and the Commit phase is beginning.
See the contents of the log file for the C:\Octopus\Tentacle\Applications\AwesomeService.1.0.2\content\AwesomeService.exe assembly's progress.
The file is located at C:\Octopus\Tentacle\Applications\AwesomeService.1.0.2\content\AwesomeService.InstallLog.
Committing assembly 'C:\Octopus\Tentacle\Applications\AwesomeService.1.0.2\content\AwesomeService.exe'.
Affected parameters are:
   logtoconsole = 
   i = 
   logfile = C:\Octopus\Tentacle\Applications\AwesomeService.1.0.2\content\AwesomeService.InstallLog
   assemblypath = C:\Octopus\Tentacle\Applications\AwesomeService.1.0.2\content\AwesomeService.exe

The Commit phase completed successfully.

The transacted install has completed.

2011-07-08 19:31:28 DEBUG  A web.config file was not found, so no IIS configuration will be performed.
2011-07-08 19:31:28 INFO   Deployment complete!

(btw, if this appears as a double post, i can’t get to my original post which was improperly placed in “Questions” to remove it)

At a guess I’d say the problem is related to 64 or 32bit. On a 64bit machine, I believe the 64bit version of InstallUtil gets invoked, which may then fail on a 32bit assembly. Can you confirm:

  1. If the assembly is built for x86 or x64 or Any CPU?
  2. Whether the Windows 7 machine is running a 32-bit version of Windows

I’m setting up automated builds at the moment so I’ll be able to turn around fixes to bugs like this in the future much quicker.

I just saw in your other thread that the Win7 machine is 32bit. Compiling the project as Any CPU should get around the problem, but I’ll put some cycles into investigating compatibility issues between x86 and x64.

You were absolutely correct, Paul. Switching the build to “Any CPU” resulted in 3 successful deployments.

Edit: I found out how to uninstall an existing service in my installer here:

I’ll look into ways to auto uninstall and start the service. For now,
you could do it with a Deploy.ps1 powershell script. From: cmcbride
Sent: Tuesday, 12 July 2011 4:56 AM
To: paul@octopusdeploy.com
Subject: Re: Windows Service Installation [Problems]