Windows Server 2019 Prevents Freshly Compiled DLL to be Saved Within User's Documents

An application which reads C# source code and compiles it to a DLL is throwing and error when trying to save this DLL to disk within the user's Documents folder, e.g "c:\Users\<user>\Documents\myapplication\some-folder\new.DLL", the application throws an exception which is caused by Windows Server 2019 claiming that the "path-does-not-exist".

Let me assure you, the path does exist:

  • What works sometimes: Add the user to group "Power Users"

  • What works always: Add the user to group "Administrators"

The latter is (should not be) not an option.

  • Windows Server 2019
  • The application is run by the user that owns the "Documents" folder
  • The application can create, rename, delete, read, write any other files or folders
  • The folder in question is exempted from antivirus, defenders, etc.

My educated guess that the application's behaviour can be seen as malicious (which it is not!, it's a game that allows mission scripting in c# and uses that technique for speed) and something tries to protect something else here. But I do not know what and how to stop it.


The real cause for this problem was that the process creating the DLL file was started by a user accessing the server remotely (e.g. with RDP). Only then an obscure windows group policy template setting hits: “Use separate temporary folders for each session” (see: https://devblogs.microsoft.com/oldnewthing/20110125-00/?p=11673).

So, the exception thrown

> System.Exception: (0,0): error CS0016: Could not write to output file
> "c:\Users\theuser\Documents\somefolder\new.dll" -- "The directory name is invalid."

is totally misleading: The invalid directory name is not in the path the DLL is to be created in, but actually part of the temporary-file path set in the TEMP or TMP environment variable (e.g. the “2” in “TMP=C:\Users...\AppData\Local\Temp\2”).

You can check the current values of TEMP and TMP by using the set command in a command line window. “Current” is highlighted, because “current” may well differ from “settings” (e.g. in My Account, environment).