New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Environment.SystemDirectory from GetFolderPath(System) on Windows #83593
Conversation
stephentoub
commented
Mar 17, 2023
Method | Toolchain | Mean | Error | StdDev | Ratio | Code Size | Allocated | Alloc Ratio |
---|---|---|---|---|---|---|---|---|
SystemDir | \main\corerun.exe | 1,469.60 ns | 9.071 ns | 7.082 ns | 1.00 | 1,986 B | 64 B | 1.00 |
SystemDir | \pr\corerun.exe | 53.36 ns | 0.618 ns | 0.516 ns | 0.04 | 2,152 B | 64 B | 1.00 |
I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label. |
I thought @jkotas had reasons why we shouldn't do this, but I could be wrong. IIRC, it was differences in behavior between https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getsystemdirectoryw |
If there's a meaningful functional difference, we obviously should close this. We should also be very hesitant to add an analyzer (#83591). |
I see Jan's comment at dotnet/aspnetcore#47269 (comment). I guess we're not sure if System is one of the ones affected, so better safe than sorry... That said, I think this would primarily be about corner-case compat. As a user reading our docs and trying to understand whether to use |
Yes, it is about compat for non-mainstream Windows configurations. I have stepped through the Windows implementation of ShGetFolderPath and it has many special cased situations (registry overrides, appcontrainers, ...). It is hard to tell whether any of those special cases matter for system directory. runtime/src/libraries/System.Runtime.Extensions/tests/System/EnvironmentTests.cs Lines 384 to 393 in c8f9f29
|
src/libraries/System.Private.CoreLib/src/System/Environment.Win32.cs
Outdated
Show resolved
Hide resolved
Interestingly, this test also assumes that the two variants are the same in all other cases. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
Any reason not to also do it for .Windows with GetWindowsDirectoryW? |
There is no distinction between .Win32.cs and .Windows.cs anymore. It is left-over from the UWP days. *.Win32.cs files can be renamed or merged into .Windows.cs files, nobody bothered to do it just yet. |
Oh I meant SpecialFolder.Windows. |