Skip to content

Crash during deletion of temp folder #201

Description

@mallibone

After Windows Server Update (KB5075902, KB5075999, KB890830) the T4 template execution fails with the following Exception:

System.AggregateException: One or more errors occurred. (Das Verzeichnis ist nicht leer. : 'C:\Users\Gnabber\AppData\Local\Temp\4\tmpD02.tmpdir')
 ---> System.IO.IOException: Das Verzeichnis ist nicht leer. : 'C:\Users\Gnabber\AppData\Local\Temp\4\tmpD02.tmpdir'
   at System.IO.FileSystem.RemoveDirectoryInternal(String fullPath, Boolean topLevel, Boolean allowDirectoryNotEmpty)
   at System.IO.FileSystem.RemoveDirectory(String fullPath, Boolean recursive)
   at System.IO.Directory.Delete(String path)
   at Mono.TextTemplating.TemplatingEngine.CompileCode(IEnumerable`1 references, TemplateSettings settings, CodeCompileUnit ccu, CancellationToken token) in /_/Mono.TextTemplating/Mono.TextTemplating/TemplatingEngine.cs:line 372
   at Mono.TextTemplating.TemplatingEngine.CompileTemplateInternal(ParsedTemplate pt, String content, ITextTemplatingEngineHost host, TemplateSettings settings, CancellationToken token) in /_/Mono.TextTemplating/Mono.TextTemplating/TemplatingEngine.cs:line 277
   at Mono.TextTemplating.TemplatingEngine.ProcessTemplateAsync(ParsedTemplate pt, String content, TemplateSettings settings, ITextTemplatingEngineHost host, CancellationToken token) in /_/Mono.TextTemplating/Mono.TextTemplating/TemplatingEngine.cs:line 88
   at Mono.TextTemplating.TemplateGenerator.ProcessTemplateAsync(ParsedTemplate pt, String inputFileName, String inputContent, String outputFileName, TemplateSettings settings, CancellationToken token) in /_/Mono.TextTemplating/Mono.TextTemplating/TemplateGenerator.cs:line 269
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at System.Threading.Tasks.Task`1.get_Result()
   at Mono.TextTemplating.TextTransform.MainInternal(String[] args) in /_/dotnet-t4/TextTransform.cs:line 226
   at Mono.TextTemplating.TextTransform.Main(String[] args) in /_/dotnet-t4/TextTransform.cs:line 42

When inspecting the folder manually it is empty. Could be some weird timing issue from the OS? Since this however totally blocks the generation I would suggest to either wrap the folder deletion in a try/catch or make the deletion of the folder recursive or both in TemplatingEngine.cs:

if (!args.Debug && !r.Errors.HasErrors) {
    r.TempFiles.Delete ();
    try {
        Directory.Delete (tempFolder, true);
    } catch (IOException) {
        // the directory is in the system temp folder and will be cleaned up by the OS
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions