docs icon indicating copy to clipboard operation
docs copied to clipboard

`Environment.GetEnvironmentVariable` on Unix: Clarify that it only sees environment-variable modifications made by *managed* callers, not also by native libraries

Open mklement0 opened this issue 1 year ago • 0 comments

Describe the issue or suggestion

Of technical necessity, on Unix-like platforms (but not on Windows), .NET maintains a private copy of the process environment block that is only seen by and can only be modified by managed callers, namely via Environment.SetEnvironmentVariable (for background information, see https://github.com/dotnet/runtime/issues/9529), which has two ramifications for P/Invoke calls to native libraries:

  • Native libraries do NOT see in-process environment changes performed via Environment.SetEnvironmentVariable.

    • This already is documented, namely in System.Environment.SetEnvironmentVariable:

      • On non-Windows systems, calls to the SetEnvironmentVariable(String, String) method have no effect on any native libraries that are, or will be, loaded.

  • Conversely, in-process environment modifications made by native libraries are not seen by managed callers.


Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

mklement0 avatar Feb 07 '24 15:02 mklement0