Support was added to be able to set an environment variable to the empty string using Environment.SetEnvironmentVariable(String, String). As part of this work, the behavior of setting the ProcessStartInfo.Environment and ProcessStartInfo.EnvironmentVariables properties was changed to be consistent with that of Environment.SetEnvironmentVariable(String, String).
Previous behaviorPreviously:
Environment.SetEnvironmentVariable("TEST", string.Empty)
and Environment.SetEnvironmentVariable("TEST", null)
deleted the environment variable.ProcessStartInfo.Environment["TEST"] = string.Empty
and ProcessStartInfo.Environment["TEST"] = null
set the environment variable in the child process to an empty value.Starting in .NET 9:
Environment.SetEnvironmentVariable("TEST", string.Empty)
sets the environment variable value to an empty value. Environment.SetEnvironmentVariable("TEST", null)
behavior is unchanged, that is, it still deletes the environment variable.ProcessStartInfo.Environment["TEST"] = null
deletes the environment variable. ProcessStartInfo.Environment["TEST"] = string.Empty
behavior is unchanged, that is, it still sets the environment variable to an empty value..NET 9 Preview 6
Type of breaking changeThis change is a behavioral change.
Reason for changeBefore this change, it wasn't possible to use Environment.SetEnvironmentVariable(String, String) to set an environment variable to an empty value, which is a valid environment variable value on all supported platforms.
Recommended actionTo delete an environment variable using Environment.SetEnvironmentVariable(String, String), change your code to pass null
instead of string.Empty
as the value argument.
To set the environment variable to an empty value using ProcessStartInfo.Environment or ProcessStartInfo.EnvironmentVariables, change your code to set these properties to string.Empty
instead of to null
.
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide. Additional resources In this articleWas this page helpful?
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4