-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Environment.ProcessPath shouldn't be marked as nullable #66288
Copy link
Copy link
Closed
Labels
Description
My application is explicit marked as windows only by using -windows. The docs say Returns null when the path is not available. but in which case can this be true? You cannot move/delete/rename the executable when its running (at least under Windows). Also the implementation doesn't return null anywhere:
runtime/src/libraries/System.Private.CoreLib/src/System/Environment.Windows.cs
Lines 95 to 110 in 0022738
| private static string? GetProcessPath() | |
| { | |
| var builder = new ValueStringBuilder(stackalloc char[Interop.Kernel32.MAX_PATH]); | |
| uint length; | |
| while ((length = Interop.Kernel32.GetModuleFileName(IntPtr.Zero, ref builder.GetPinnableReference(), (uint)builder.Capacity)) >= builder.Capacity) | |
| { | |
| builder.EnsureCapacity((int)length); | |
| } | |
| if (length == 0) | |
| throw Win32Marshal.GetExceptionForLastWin32Error(); | |
| builder.Length = (int)length; | |
| return builder.ToString(); | |
| } |
Reactions are currently unavailable