Automationtool error: failed to delete AutomationUtils.Automation.dll

We updated our engine to 4.21 and face the following error, when building from commandline:

Failed to delete file ‘S:\Unreal\UE_4.21\Engine\Binaries\DotNET\AutomationUtils.Automation.dll’
It seems strange that the very process which loaded the file, tries to delete it.

Our commandline:

call RunUAT BuildCookRun -project="%Projectfile%" -noP4 -platform=Win64 -clientconfig=Development -serverconfig=Development -cook -compile -build -stage -pak

There is no antivirus installed (this system is windows 10,and disabled windowsdefender for testing purposes after error occured first time. no difference). We use VS 2017 with WIndows 10 SDK: We tested on 2 machines(Both windows 10, same vs and sdk) and had that behaviour on both.

We did not have that issue in 4.19 (we had to skip 4.20). The full log.txt:

Automation.ParseCommandLine: Parsing command line: BuildCookRun -project=S:\Git\ProjContDev\ProjCont.uproject -noP4 -platform=Win64 -clientconfig=Development -serverconfig=Development -cook -compile
Automation.Process: Setting up command environment.
InternalUtils.SafeFileExists: SafeFileExists S:\Unreal\UE_4.21\Engine\Binaries\DotNET\AutomationTool.exe=True
InternalUtils.GetEnvironmentVariable: GetEnvironmentVariable uebp_LOCAL_ROOT=
InternalUtils.GetEnvironmentVariable: GetEnvironmentVariable uebp_LOCAL_ROOT=
InternalUtils.GetEnvironmentVariable: GetEnvironmentVariable uebp_EngineSavedFolder=
CommandUtils.SetEnvVar: SetEnvVar uebp_EngineSavedFolder=S:/Unreal/UE_4.21/Engine/Programs/AutomationTool/Saved
InternalUtils.GetEnvironmentVariable: GetEnvironmentVariable uebp_EngineSavedFolder=S:/Unreal/UE_4.21/Engine/Programs/AutomationTool/Saved
InternalUtils.GetEnvironmentVariable: GetEnvironmentVariable uebp_CSVFile=
InternalUtils.GetEnvironmentVariable: GetEnvironmentVariable uebp_LogFolder=
CommandUtils.SetEnvVar: SetEnvVar uebp_LogFolder=S:/Unreal/UE_4.21/Engine/Programs/AutomationTool/Saved/Logs
InternalUtils.SafeDeleteFile: SafeDeleteFile S:\Unreal\UE_4.21\Engine\Programs\AutomationTool\Saved\Logs\Log.txt
InternalUtils.GetEnvironmentVariable: GetEnvironmentVariable uebp_FinalLogFolder=
CommandUtils.SetEnvVar: SetEnvVar uebp_FinalLogFolder=S:/Unreal/UE_4.21/Engine/Programs/AutomationTool/Saved/Logs
InternalUtils.SafeFileExists: SafeFileExists C:\WINDOWS\system32\robocopy.exe=True
InternalUtils.SafeFileExists: SafeFileExists C:\WINDOWS\system32\mount.exe=False
InternalUtils.SafeFileExists: SafeFileExists C:\WINDOWS\Sysnative\mount.exe=False
InternalUtils.SafeFileExists: SafeFileExists C:\WINDOWS\system32\cmd.exe=True
CommandUtils.SetEnvVar: SetEnvVar MallocNanoZone=0
InternalUtils.GetEnvironmentVariable: GetEnvironmentVariable uebp_UATChildInstance=0
InternalUtils.SafeDeleteDirectory: SafeDeleteDirectory S:\Unreal\UE_4.21\Engine\Binaries\DotNET\AutomationScripts
InternalUtils.SafeDeleteFile: SafeDeleteFile S:\Unreal\UE_4.21\Engine\Binaries\DotNET\AutomationUtils.Automation.dll
InternalUtils.SafeDeleteFile: WARNING: Failed to delete file S:\Unreal\UE_4.21\Engine\Binaries\DotNET\AutomationUtils.Automation.dll in 10 attempts.
InternalUtils.SafeDeleteFile: WARNING: Exception in mscorlib: Der Zugriff auf den Pfad "S:\Unreal\UE_4.21\Engine\Binaries\DotNET\AutomationUtils.Automation.dll" wurde verweigert.
InternalUtils.SafeDeleteFile:          Stacktrace:    bei System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
InternalUtils.SafeDeleteFile:             bei System.IO.File.InternalDelete(String path, Boolean checkHost)
InternalUtils.SafeDeleteFile:             bei AutomationTool.InternalUtils.SafeDeleteFile(String Path, Boolean bQuiet) in D:\Build\++UE4\Sync\Engine\Saved\CsTools\Engine\Source\Programs\AutomationTool\AutomationUtils\Utils.cs:Zeile 100.
Log.WriteException: ==============================================================================
Log.WriteException: ERROR: Failed to delete file 'S:\Unreal\UE_4.21\Engine\Binaries\DotNET\AutomationUtils.Automation.dll'
Log.WriteException:        (see S:\Unreal\UE_4.21\Engine\Programs\AutomationTool\Saved\Logs\Log.txt for full exception trace)
Log.WriteException: 
Log.WriteException: AutomationException: Failed to delete file 'S:\Unreal\UE_4.21\Engine\Binaries\DotNET\AutomationUtils.Automation.dll'
Log.WriteException:    bei AutomationTool.CommandUtils.DeleteFile(String FileName) in D:\Build\++UE4\Sync\Engine\Saved\CsTools\Engine\Source\Programs\AutomationTool\AutomationUtils\CommandUtils.cs:Zeile 488.
Log.WriteException:    bei AutomationTool.ScriptCompiler.CleanupScriptsAssemblies() in D:\Build\++UE4\Sync\Engine\Saved\CsTools\Engine\Source\Programs\AutomationTool\AutomationUtils\ScriptCompiler.cs:Zeile 325.
Log.WriteException:    bei AutomationTool.ScriptCompiler.FindAndCompileAllScripts(String ScriptsForProjectFileName, List`1 AdditionalScriptsFolders) in D:\Build\++UE4\Sync\Engine\Saved\CsTools\Engine\Source\Programs\AutomationTool\AutomationUtils\ScriptCompiler.cs:Zeile 69.
Log.WriteException:    bei AutomationTool.Automation.Process(String[] Arguments, StartupTraceListener StartupListener) in D:\Build\++UE4\Sync\Engine\Saved\CsTools\Engine\Source\Programs\AutomationTool\AutomationUtils\Automation.cs:Zeile 502.
Log.WriteException:    bei AutomationTool.Program.MainProc(String[] Arguments, StartupTraceListener StartupListener) in D:\Build\++UE4\Sync\Engine\Saved\CsTools\Engine\Source\Programs\AutomationTool\Program.cs:Zeile 173.
Log.WriteException:    bei AutomationTool.Program.<>c__DisplayClass1_0.<Main>b__2() in D:\Build\++UE4\Sync\Engine\Saved\CsTools\Engine\Source\Programs\AutomationTool\Program.cs:Zeile 99.
Log.WriteException:    bei AutomationTool.InternalUtils.RunSingleInstance(Func`1 Main) in D:\Build\++UE4\Sync\Engine\Saved\CsTools\Engine\Source\Programs\AutomationTool\AutomationUtils\Utils.cs:Zeile 725.
Log.WriteException:    bei AutomationTool.Program.Main() in D:\Build\++UE4\Sync\Engine\Saved\CsTools\Engine\Source\Programs\AutomationTool\Program.cs:Zeile 99.
Log.WriteException: ==============================================================================
Program.Main: AutomationTool exiting with ExitCode=1 (Error_Unknown)

Hello, I have the same problem, have you fixed it?

we fixed it by removing the “-compile” switch which should result in it not recompiling itself. If the sourceversion is used or the problem still occurs, replacing the switch with “-nocompile” should do the trick.

Yes, added my solution as answer.

Also, I ran into the same problem and I had to recover the AutomationUtils folder that had been removed by a previous “-compile” command in order to make the “-nocompile” command run succesfully

How did you managed to recover the AutomationUtils folder?

We are building our own InstalledBuild so we have archives of our engine files. I recovered it from there.

If you can’t do that, I guess that rebuilding an installed build, or if you are using launcher version, hitting some repair button or redownloading your engine version should do the trick.

Oh ok, we are on a custom build too, I can recover files from the archive. I thoung tehre was a way to recreate it from the RunUAT for example