File on Projected File System is corrupted after being edited in MS Visual Studio

Oleg T 6 Reputation points
2021-07-30T21:31:27.82+00:00

Hello,
I'm working on a project that uses ProjFS.

Turns out, if you project a virtual file to the filesystem, then open it in Microsoft Visual Studio, edit and save it, and then revert it back to the original virtual file using PrjDeleteFile, the file ends up in a bad state: it is shown when listing the directory (as expected), but when you try to open it, Windows says it doesn't exist. After that the file is stuck in this corrupted state forever: it cannot be opened or deleted (until you restart the computer).
I think it has to do something with how MS VS saves files (using temporary files and renaming) because if you do the same steps using Notepad or Visual Studio Code instead of Microsoft Visual Studio, "PrjDeleteFile" successfully reverts it back to its original state, and it can be edited again.
I tried Microsoft Visual Studio Community 2019, on Windows 10, 20H2 (build 19042.1110), as well as Microsoft Visual Studio Professional 2017, Windows 10, 1909 (build 18363.1679), the behavior is just the same.
I've made a simple reproducing app: it projects a virtual file of zero length in C:\Temp\Virt1\temp, then if you edit it in MS VS and revert the file back (pressing <enter> in the app), the file becomes corrupted.
Here's the link to it: https://github.com/lightln2/ProjFs-File-Corruption

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,426 questions
{count} votes