Uh oh!
There was an error while loading. Please reload this page.
Use GetTempPath2W if available. - #72452
Conversation
ghost
commented
Jul 19, 2022
Tagging subscribers to this area: @dotnet/area-system-io Issue DetailsSince Windows 11 there is a new API to get the temporary files path called This PR tries to find I also fixed a bug where the original
|
jkotas
commented
Jul 19, 2022
Does this behavior change need to be treated as a breaking change? |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
danmoseley
commented
Jul 19, 2022
This would be something like -- I wrote a file to temp, upgrade my .NET or OS, and try to read it? That seems unlikely to be something we want to guarantee. In general it is good to not assume that a reboot will preserve temp. |
teo-tsirpanis
commented
Jul 19, 2022
And the path would change only if the program runs as SYSTEM. Most user apps are unaffected. |
danmoseley
commented
Jul 19, 2022
Have people tried running .NET code as SYSTEM? |
GrabYourPitchforks
commented
Jul 19, 2022
It's not uncommon for Windows services to run as SYSTEM. It's also possible that |
Uh oh!
There was an error while loading. Please reload this page.
…s.cs Co-authored-by: Stephen Toub <stoub@microsoft.com>
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
…s.cs Co-authored-by: David Cantú <dacantu@microsoft.com>
danmoseley
commented
Aug 10, 2022
GetGCMemoryInfo failure is already resolved. |
danmoseley
commented
Aug 10, 2022
@teo-tsirpanis could you please resolve the conflict so we can merge? |
teo-tsirpanis
commented
Aug 10, 2022
Conflicts were resolved. |
danmoseley
commented
Aug 11, 2022
Failure is #73679 |
| // | ||
| // IsWow64Process2 is only available on Windows 10+, so we will perform run-time introspection via indirect load | ||
| if (NativeLibrary.TryGetExport(NativeLibrary.Load(Interop.Libraries.Kernel32), "IsWow64Process2", out IntPtr isWow64Process2Ptr)) | ||
| IntPtr kernel32 = Interop.Kernel32.LoadLibraryEx(Interop.Libraries.Kernel32, 0, Interop.Kernel32.LOAD_LIBRARY_SEARCH_SYSTEM32); |
There was a problem hiding this comment.
Unrelated change to make load library more secure?
adamsitnik
left a comment
There was a problem hiding this comment.
LGTM, thank you for your contribution @teo-tsirpanis !
adamsitnik
commented
Aug 11, 2022
The failure is unrelated (#73679), merging |
Since Windows 11 there is a new API to get the temporary files path called
GetTempPath2. This API returns a directory inaccessible to non-SYSTEM processes if the calling process runs as SYSTEM, and it is recommended to call this function instead ofGetTempPath.This PR tries to find
GetTempPath2Wand uses that, otherwise it falls back toGetTempPathW.I also fixed a bug where the original
GetTempPathWP/Invoke was not marked withSetLastErrorand would fail withOperation Completed Successfulyin case of a failure.