My problem is that somewhere, one way or another, and only sporadically, Environment.CurrentDirectorygets the value C:\Windows\System32when my test suite is running. Several tests depend on the current directory, and as a result they do not work.
I searched in my project and confirmed that none of my codes set this property. I use numerous third-party libraries, although, in my suspicion, one of them modifies the current directory.
I did a specific search specifically for the current directory, changing to system32, but I came up empty. Are there any general reasons why this could happen?
Another approach, which similarly turned out to be empty, is this: how can I track down a criminal? As far as I know, I can't have Visual Studio break somewhere when the value has changed. Since this is an environment variable in .NET libraries, I cannot set a breakpoint in the installer.
I was thinking about using procmon or something else that hopefully records when the current directory has changed, but then it does not pause execution when this happens, so I still don't know where this happened.
I just don't understand how to debug this. Any ideas? Or is my only way to save Environment.CurrentDirectoryreadonly in the global field and refer exclusively to what is in my code, allowing it to change the current directory with impunity?