1

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.

kenlukas
  • 3,101
  • 2
  • 16
  • 26
Murmanfurt
  • 31
  • 5
  • Check the permissions of each folder in the path to see if one of them does not allow the user full control. – Michael Hampton Aug 03 '20 at 14:06
  • If file creation is blocked,Defender will send an event log(List:https://docs.microsoft.com/en-us/windows/security/threat-protection/microsoft-defender-antivirus/troubleshoot-microsoft-defender-antivirus)you can check there for events to discard that is anti-malware the problem.App is running under same user that is trying to save file?Everything inside documents folders is allowed by same user. But probably folder was created during installation under different user or admin or trust installer user.Like Michael told,check folder permissions to allow full control to the user,all users for test – DefToneR Aug 03 '20 at 14:20
  • @Michael Hampton: User is owner all the way down from "Documents". Permissions are "Full Control" (and all others except "Special Perimissions") on all folders in path – Murmanfurt Aug 03 '20 at 14:24
  • @Deftoner: The application is run by the user that owns the "Documents" folder". It has never run under any other user. DLL saving also fails in the first-installation process that just has created all other files and folders below and including "myapplication". – Murmanfurt Aug 03 '20 at 14:26
  • @Deftoner: I'll replicate problem and check the event log – Murmanfurt Aug 03 '20 at 14:27
  • Murphy :-( not reproducable. Must wait for suspicious(?) mission script/dll – Murmanfurt Aug 04 '20 at 16:27

1 Answers1

2

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).

Murmanfurt
  • 31
  • 5
  • Thank you for returning with a solution! Please mark this as an answer when the site permits it. – Paul Nov 29 '21 at 19:13