Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breaking change - GetEnvironmentVariable / GetEnvironmentVariables treatment of empty string variables #103259

Closed
flakey-bit opened this issue Jun 11, 2024 · 8 comments

Comments

@flakey-bit
Copy link

Description

I've noticed that the treatment of empty string environment variables appears to have changed between .NET7 and .NET8 on Linux

  • Assuming the environment variable My__Variable__name was set to an empty string in the shell and exported
  • Under .NET7 Environment.GetEnvironmentVariable("My__Variable__name") was returning null
  • Under .NET8 Environment.GetEnvironmentVariable("My__Variable__name") is returning an empty string

I couldn't see this listed under the breaking changes section.

Reproduction Steps

export My__Variable__name=""
Environment.GetEnvironmentVariable("My__Variable__name");

Expected behavior

Perhaps the behaviour change is deliberate, but it should probably be called out

Actual behavior

?

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jun 11, 2024
@flakey-bit
Copy link
Author

Possibly relates to #50554

@vcsjones vcsjones added area-System.Runtime and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Jun 11, 2024
@flakey-bit
Copy link
Author

I guess this "could" be due to the debian base image changing between mcr.microsoft.com/dotnet/sdk:8.0 and mcr.microsoft.com/dotnet/sdk:7.0

However I'd have thought an empty string environment variable is an empty string environment variable

Before invoking the .NET process we're logging

printf %s "$My__Variable__name" | od -vtc -to1

and it outputs

0000000

@jkotas
Copy link
Member

jkotas commented Jun 11, 2024

Under .NET7 Environment.GetEnvironmentVariable("My__Variable__name") was returning null

It does not repro for me. Here is transcript of what I have done to reproduce it:

C:\>docker run -it mcr.microsoft.com/dotnet/sdk:7.0
root@08f300bf3cee:/# dotnet new console -o test
The template "Console App" was created successfully.

Processing post-creation actions...
Restoring /test/test.csproj:
  Determining projects to restore...
  Restored /test/test.csproj (in 87 ms).
Restore succeeded.


root@08f300bf3cee:/# cd test/
root@08f300bf3cee:/test# echo "Console.WriteLine(Environment.GetEnvironmentVariable(\"My__Variable__name\") is null);" > Program.cs
root@08f300bf3cee:/test# dotnet build
MSBuild version 17.7.6+77d58ec69 for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
  test -> /test/bin/Debug/net7.0/test.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:03.16
root@08f300bf3cee:/test# /test/bin/Debug/net7.0/test
True
root@08f300bf3cee:/test# export My__Variable__name=""
root@08f300bf3cee:/test# /test/bin/Debug/net7.0/test
False
root@08f300bf3cee:/test# exit
exit

@jkotas
Copy link
Member

jkotas commented Jun 11, 2024

Could you please share exact repro steps?

@jkotas jkotas added the needs-author-action An issue or pull request that requires more info or actions from the author. label Jun 11, 2024
Copy link
Contributor

This issue has been marked needs-author-action and may be missing some important information.

@flakey-bit
Copy link
Author

@jkotas thanks very much for your time already spent looking into this.

While I can reproduce the issue on my CI server (JetBrains TeamCity), I'm unable to reproduce it locally/with a docker image and I've given up in my attempts to do so.

Apologies for not doing the leg-work initially 💚& thus taking your time.

Have ended up amending the shell script to avoid creating empty variables.

@jkotas
Copy link
Member

jkotas commented Jun 11, 2024

CI server (JetBrains TeamCity),

What is the distro that this CI server runs on?

It is possible that there may be a bug that repros on some Linux distros only.

@flakey-bit
Copy link
Author

What is the distro that this CI server runs on?
It is possible that there may be a bug that repros on some Linux distros only.

The build step is running within the dotnet SDK docker image (mcr.microsoft.com/dotnet/sdk:7.0 or mcr.microsoft.com/dotnet/sdk:8.0 respectively)

The build agents are probably running on a variety of Linux distros. If you think the underlying Linux distro could be relevant, I can look into it.

@tannergooding tannergooding removed the needs-author-action An issue or pull request that requires more info or actions from the author. label Jun 24, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jul 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants