C#: Problem with File.WriteAllText to temp file of a different process

Veröffentlicht von

Interesting problem with C# and File.WriteAllText does not work.

Today I had an interesting problem. My program ist a small debug helper, which is launched by application one, which lauchnes application two.

The information exchange is done via an INI file, application one creates a temporary INI file on the temp folder. In my application I was changing the content of the INI file and tried to write the new content in the INI file.

However it did not work. File.WriteAllText did not work. No content was written to the INI file. No exception was thrown. If I used a different path or filename it worked. My assumption was, that this would be some sort of security thing, that one application could not just overwrite the temp file of a different application. However editing with Visual Studio Code and Notepad++ worked.

My workaround for the problem was to write the content to a different file first. Then use File.Copy to copy the new file over the old one.

Kommentar hinterlassen

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert