This message was deleted.
# dotnet
s
This message was deleted.
b
Maybe? But I don't know if we know the type of
pair.Key
is
string
at compile-time so
env[pair.key] = ...;
might give you an error?
Here's your answer I think:
We need to get the KVP first.
Did you find that we were losing environment variables doing it this way?
t
Ah, that makes sense. There's no problems, I was just confused why the second type was
object
and not
string
.
b
Have you personally tried passing environment variables from your system into pulumi? I was just messing with this code in a console app and I found some issues (thanks for bringing it up, lol). First of all,
element
is of type
System.Collection.DictionaryEntry?
. And none of them satisfied
KeyValuePair<string, object>
,
KeyValuePair<string, string>
, or
KeyValuePair<string, string?>
... which is concerning I actually had to do this to get working:
Copy code
var env = Environment.GetEnvironmentVariables();
            foreach (DictionaryEntry? element in env)
            {
                if (element is null || !element.HasValue)
                    continue;

                if (element.Value.Key is string keyStr
                    && element.Value.Value != null
                    && element.Value.Value is string valueStr)
                    Console.WriteLine($"[{keyStr}] = {valueStr}");
            }
@enough-garden-22763 this may be an oversight on my part we might want a test that system environment vars are making it into pulumi execution, I think my
is KeyValuePair<string, object>
check might never be satisfied currently
p
But yeah
foreach (DictionaryEntry entry in Environment.GetEnvironmentVariables())
should do the trick and then checking the key & value
b
that's a pretty big faux pas on my part yikes
@prehistoric-coat-10166 unfortunately with the nullable reference types enabled that function is returning nullable dictionary entries for some reason so that added null check complexity in my example above is necessary
t
This is redundant:
Copy code
element.Value.Value != null
                    && element.Value.Value is string valueStr
If it's null, it won't say it's a string
b
you are correct, that is because I was doing this first and was getting an error and switched to what I posted
p
Copy code
if (element.Value.Key is string keyString
                    && element.Value.Value is string valueString)
                {
                    env[keyString] = valueString;
                }
Should work (with the element null check)
e
Hey team just seeing this discussion here 👋
System environment vars are making it into pulumi execution indeed, we don’t have a test checked in but some test I’ve done indicate its’ happening.
b
Cool so we should be good with your PR, then. Awesome.
p
Yeah, deleted code is best code!
🙌 1
Do we want to still allow the nullable environment variables on our end? With for example default value of empty to consistently "unset" environment variables until CliWrap allows nulls?
Although I guess it might just as easy on the users' side to use
ValueWhichMayBeNull ?? ""
Heh, actually the problem seems to go deeper to
Process
https://github.com/dotnet/runtime/issues/34446