Skip to content

Commit

Permalink
[release/7.0-staging] dotnet.exe prints error messages to console whe…
Browse files Browse the repository at this point in the history
…n launched with empty DOTNET_MULTILEVEL_LOOKUP (#87734)

* dotnet.exe prints error messages to console when launched with empty DOTNET_MULTILEVEL_LOOKUP

* reuse err variable instead of invoking GetLastError another time

Co-authored-by: Vitek Karas <10670590+vitek-karas@users.noreply.github.com>

* another useless call to GetLastError

* add tests

* fix spacing

* add asserts to another test

* delete empty instruction

* use EnableTracingAndCaptureOutputs

* check just that no error is logged

* rollback change correctly

---------

Co-authored-by: pedrobsaila <badrebsaila@outlook.com>
Co-authored-by: Badre BSAILA <54767641+pedrobsaila@users.noreply.github.com>
Co-authored-by: Vitek Karas <10670590+vitek-karas@users.noreply.github.com>
  • Loading branch information
4 people committed Jun 26, 2023
1 parent 6141941 commit 083831e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,8 @@ public void AppHost_FrameworkDependent_GlobalLocation_Succeeds(bool useRegistere
.Execute()
.Should().Pass()
.And.HaveStdOutContaining("Hello World")
.And.HaveStdOutContaining(sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion);
.And.HaveStdOutContaining(sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion)
.And.NotHaveStdErr();

// Verify running from within the working directory
Command.Create(appExe)
Expand All @@ -336,7 +337,8 @@ public void AppHost_FrameworkDependent_GlobalLocation_Succeeds(bool useRegistere
.Execute()
.Should().Pass()
.And.HaveStdOutContaining("Hello World")
.And.HaveStdOutContaining(sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion);
.And.HaveStdOutContaining(sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion)
.And.NotHaveStdErr();
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/installer/tests/HostActivation.Tests/StartupHooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ public void Muxer_activation_of_Empty_StartupHook_Variable_Succeeds()
.CaptureStdErr()
.Execute()
.Should().Pass()
.And.HaveStdOutContaining("Hello World");
.And.HaveStdOutContaining("Hello World")
.And.NotHaveStdErr();
}

// Run the app with a startup hook assembly that depends on assemblies not on the TPA list
Expand Down
8 changes: 6 additions & 2 deletions src/native/corehost/hostmisc/pal.windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,14 +570,18 @@ bool pal::getenv(const char_t* name, string_t* recv)
auto err = GetLastError();
if (err != ERROR_ENVVAR_NOT_FOUND)
{
trace::error(_X("Failed to read environment variable [%s], HRESULT: 0x%X"), name, HRESULT_FROM_WIN32(GetLastError()));
trace::warning(_X("Failed to read environment variable [%s], HRESULT: 0x%X"), name, HRESULT_FROM_WIN32(err));
}
return false;
}
auto buf = new char_t[length];
if (::GetEnvironmentVariableW(name, buf, length) == 0)
{
trace::error(_X("Failed to read environment variable [%s], HRESULT: 0x%X"), name, HRESULT_FROM_WIN32(GetLastError()));
auto err = GetLastError();
if (err != ERROR_ENVVAR_NOT_FOUND)
{
trace::warning(_X("Failed to read environment variable [%s], HRESULT: 0x%X"), name, HRESULT_FROM_WIN32(err));
}
return false;
}

Expand Down

0 comments on commit 083831e

Please sign in to comment.