File in use when upgrading ServiceControl from 5.2.0

When upgrading from servicecontrol 5.2.0 to 5.2.4 or 5.2.3, I got the following error message:

System.IO.IOException: The process cannot access the file 'C:\Program Files (x86)\Particular Software\Particular.ServiceControl\System.ServiceProcess.ServiceController.dll' because it is being used by another process.
   at System.IO.FileSystem.DeleteFile(String fullPath)
   at System.IO.FileInfo.Delete()
   at ServiceControlInstaller.Engine.FileSystem.FileUtils.DeleteDirectory(String path, Boolean recursive, Boolean contentsOnly, String[] excludes) in /_/src/ServiceControlInstaller.Engine/FileSystem/FileUtils.cs:line 49
   at ServiceControlInstaller.Engine.Instances.ServiceControlInstance.UpgradeFiles(String zipFilePath) in /_/src/ServiceControlInstaller.Engine/Instances/ServiceControlInstance.cs:line 197
   at ServiceControl.Config.Framework.Modules.ServiceControlInstallerBase.Upgrade(ServiceControlBaseService instance, ServiceControlUpgradeOptions upgradeOptions, IProgress`1 progress) in /_/src/ServiceControl.Config/Framework/Modules/InstallerModule.cs:line 126
   at ServiceControl.Config.Commands.UpgradeServiceControlInstanceCommand.<>c__DisplayClass3_0.<UpgradeServiceControlInstance>b__0() in /_/src/ServiceControl.Config/Commands/UpgradeServiceControlInstanceCommand.cs:line 152
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
   at ServiceControl.Config.Commands.UpgradeServiceControlInstanceCommand.UpgradeServiceControlInstance(InstanceDetailsViewModel model, ServiceControlInstance instance, ServiceControlUpgradeOptions upgradeOptions) in /_/src/ServiceControl.Config/Commands/UpgradeServiceControlInstanceCommand.cs:line 152
   at ServiceControl.Config.Commands.UpgradeServiceControlInstanceCommand.ExecuteAsync(InstanceDetailsViewModel model) in /_/src/ServiceControl.Config/Commands/UpgradeServiceControlInstanceCommand.cs:line 127
   at ServiceControl.Config.Framework.Commands.AwaitableAbstractCommand`1.ServiceControl.Config.Framework.Commands.ICommand<T>.Execute(T obj) in /_/src/ServiceControl.Config/Framework/Commands/AwaitableAbstractCommand.cs:line 22
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

ServiceControl was stopped before the upgrade was started.
The result was an incompletely installed 5.2.0 version, which I could no longer access. Workaround was to define a new 5.2.0 instance and copy the files from the new to the incomplete version.

What goes wrong when upgrading?

Hi @jmateman ,

We’ve had a few reports where the upgrade failed because files were still in-use / locked. We’ve made the installer more resilient to such issues and that change will be part of our next minor release:

What keeps the files in use is unknown. It could be that the instance is still running for a little while or that the file is kept in use by another process like a virusscanner.

Stopping the instance manually first before upgrading should result in enough time to release the in use files.

– Ramon

Thank you for this update!