Skip to content
Merged
Prev Previous commit
Next Next commit
Match Windows behavior for duplicate keys
  • Loading branch information
filipnavara committed Aug 26, 2021
commit 8759796e1365fe38acdaebd16020b778973907b1
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,16 @@ private static Dictionary<string, string> GetSystemEnvironmentVariables()
while (ParseEntry(blockIterator, out string? key, out string? value))
{
if (key != null && value != null)
results.Add(key, value);
{
try
{
// Add may throw if the environment block was corrupted leading to duplicate entries.
// We allow such throws and eat them (rather than proactively checking for duplication)
// to provide a non-fatal notification about the corruption.
results.Add(key, value);
}
catch (ArgumentException) { }
}

// Increment to next environment variable entry
blockIterator += IntPtr.Size;
Expand Down