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

System.Configuration.ConfigurationManager.Tests: use Assembly.Location to determine ThisApplicationPath. #112231

Merged
merged 2 commits into from
Feb 10, 2025

Conversation

tmds
Copy link
Member

@tmds tmds commented Feb 6, 2025

return Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
Assembly.GetEntryAssembly().ManifestModule.Name);
Assembly assembly = Assembly.GetEntryAssembly();
string directory = Path.GetDirectoryName(assembly.Location);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BaseDirectory is typically the directory of the entry assembly. Where is the difference in your test environment come from? Are you running the tests in some kind of atypical setup that makes BaseDirectory different from entry assembly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is as invoked from top-level build.sh with the --test argument.

The invocation ends up looking something like:

/home/tester/runtime/artifacts/bin/testhost/net10.0-linux-Debug-x64/dotnet exec --runtimeconfig System.Runtime.Caching.Tests.runtimeconfig.json --depsfile System.Runtime.Caching.Tests.deps.json /home/tester/.nuget/packages/microsoft.dotnet.xunitconsolerunner/2.9.2-beta.25080.7/build/../tools/net/xunit.console.dll System.Runtime.Caching.Tests.dll -xml testResults.xml -nologo -notrait category=IgnoreForCI -notrait category=OuterLoop -notrait category=failing 

The xunit.console.dll is not in the BaseDirectory (as shown on the command line, it comes from .nuget/packages).

This code was changed long ago in https://github.com/dotnet/corefx/pull/21006/files. I assume that change was more about the ManifestModule.Name than it was about changing to use the BaseDirectory.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was done originally to make the test compatible with single file form factors. The description of the old PR that you have linked says that it is fixing the tests for uap-aot (aka .NET Native) that was the first single file form factor.

The problem with single file is that Assembly.Location returns empty string.

I think it would be best to delete the ThisApplicationPath property and the one test that uses it. There are other more comprehensive tests OpenExeConfiguration2 and OpenExeConfiguration2_ExePath_DoesNotExist to exercise this scenario. These other tests create the files in known locations and so they do not depend on the deployment details that may change over time.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your insights! I've removed the test.

This is functionally covered other tests (OpenExeConfiguration2 and OpenExeConfiguration2_ExePath_DoesNotExist)
that do not rely on the test deployment.
@jkotas
Copy link
Member

jkotas commented Feb 10, 2025

/ba-g unrelated timeout

@jkotas jkotas merged commit cc74292 into dotnet:main Feb 10, 2025
82 of 85 checks passed
grendello added a commit to grendello/runtime that referenced this pull request Feb 11, 2025
* main:
  Code clean up in AP for NonNull* (dotnet#112027)
  JIT: Invalidate LSRA's DFS tree if we aren't running new layout phase (dotnet#112364)
  Update dependencies from https://github.com/dotnet/source-build-reference-packages build 20250204.2 (dotnet#112339)
  Add doc on OS onboarding (dotnet#112026)
  Add `TypeName` APIs to simplify metadata lookup. (dotnet#111598)
  Internal monitor impl not using coop mutex causing deadlocks on Android. (dotnet#112358)
  Do not run NAOT arm64 OSX testing on all PRs (dotnet#112342)
  Special-case empty enumerables in AsyncEnumerable (dotnet#112321)
  Have mono handle ConvertToIntegerNative for Double and Single (dotnet#112206)
  Update dependencies from https://github.com/dotnet/arcade build 20250206.4 (dotnet#112338)
  System.Configuration.ConfigurationManager.Tests: use Assembly.Location to determine ThisApplicationPath. (dotnet#112231)
  Force write of local file header when "version needed to extract" changes (dotnet#112032)
  JIT: Don't reorder handler blocks (dotnet#112292)
  [RISC-V] Synthesize some floating constants inline (dotnet#111529)
  Enable `SA1000`: Spacing around keywords (dotnet#112302)
  Fix relocs for linux-riscv64 AOT (dotnet#112331)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Configuration community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

exePath_UserLevelNone failing when testing against source-build config
2 participants