docs
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
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.
- This is currently not documented, and should be mentioned in the following topics:
- The
System.Environment.GetEnvironmentVariablemethod - The
System.Environment.GetEnvironmentVariablemethods fundamentals article.
- The
- This is currently not documented, and should be mentioned in the following topics:
Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.
- ID: 4803cbbd-7955-7443-fced-8461ee23d685
- Version Independent ID: 4734e5db-f0d4-6fa2-75cb-d0836fb12f36
- Content: System.Environment.GetEnvironmentVariable methods - .NET
- Content Source: docs/fundamentals/runtime-libraries/system-environment-getenvironmentvariable.md
- Service: dotnet-fundamentals
- GitHub Login: @gewarren
- Microsoft Alias: dotnetcontent