Skip to content

Environment.ProcessPath shouldn't be marked as nullable #66288

@Symbai

Description

@Symbai

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:

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();
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions