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

Set AppContext.BaseDirectory and the lookup path for AssemblyDirectory to the directory containing the NativeAOT module #112457

Merged
merged 10 commits into from
Mar 4, 2025

Conversation

jkoritzinsky
Copy link
Member

Fixes #112290
Fixes #90131

We already had most of the components needed to wire this up in the NativeAOT PAL and in the EH DeveloperExperience APIs, so this wasn't as bad as I thought.

…y to the directory containing the NativeAOT module
@MichalStrehovsky
Copy link
Member

Could you add a test for this? I assume since this still doesn't build, it wasn't even manually tested to work, and we definitely don't have test coverage in the tree.

@jkoritzinsky
Copy link
Member Author

Yes I need to still construct a test for this. I'll flip it to draft until I have it ready for review.

@jkoritzinsky jkoritzinsky marked this pull request as draft February 17, 2025 07:43
@jkoritzinsky jkoritzinsky marked this pull request as ready for review February 24, 2025 19:56
@jkoritzinsky
Copy link
Member Author

@MichalStrehovsky I've added a test for this.

Copy link
Member

@MichalStrehovsky MichalStrehovsky left a comment

Choose a reason for hiding this comment

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

The tests are failing but it looks reasonable to me otherwise, thanks!

Just last week I was helping someone in the Windows org who was building a DLL and wondered why they can't load a JSON file next to the DLL with AppContext.BaseDirectory.

I wonder if we should doc this as a breaking change, someone might use this and it would be nice to have guidance ready (just use the directory of the Environment.ProcessPath).

@jkoritzinsky
Copy link
Member Author

I'll mark this as a breaking change and file the doc after I fix the test and merge.

@jkoritzinsky jkoritzinsky added the breaking-change Issue or PR that represents a breaking API or functional change over a prerelease. label Feb 25, 2025
@dotnet-policy-service dotnet-policy-service bot added the needs-breaking-change-doc-created Breaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet label Feb 25, 2025
Copy link
Member

@elinor-fung elinor-fung left a comment

Choose a reason for hiding this comment

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

It might also be good to add a note to the DllImportSearchPath.AssemblyDirectory doc about Native AOT libraries.

@jkoritzinsky jkoritzinsky merged commit 7cfe5e3 into dotnet:main Mar 4, 2025
136 of 140 checks passed
@MichalStrehovsky
Copy link
Member

Native AOT outerloop runs are broken: many tests failing with "The path must be absolute":

[FAIL] Microsoft.Extensions.Hosting.Tests.HostBuilderTests.DefaultConfigIsMutable
System.ArgumentException : The path must be absolute. (Parameter 'root')
   at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String, ExclusionFilters) + 0xe0
   at Microsoft.Extensions.Hosting.HostBuilder.CreateHostingEnvironment(IConfiguration) + 0x118
   at Microsoft.Extensions.Hosting.HostBuilder.Build() + 0x3b
   at Microsoft.Extensions.Hosting.Tests.HostBuilderTests.DefaultConfigIsMutable() + 0x2c
   at Microsoft.Extensions.Hosting.Unit!<BaseAddress>+0x1db881b
   at System.Reflection.DynamicInvokeInfo.Invoke(Object, IntPtr, Object[], BinderBundle, Boolean) + 0x118

If I'm reading this right the problem is that we somehow end up using the path of argv[0] as the AppContext.BaseDirectory, but that can be a relative path relative to the current directory at process start. (I didn't actually try to debug this, I just worked backwards from the newly added test for BaseDirectory that uses argv[0] as the expected value.)

If this cannot be fixed quickly, I'd prefer this to be reverted because it's failing 100 tests and it's hard to keep an eye on outerloop with so many failures.

@jkoritzinsky
Copy link
Member Author

I'll take a look today and if I can't fix it I'll revert it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-NativeAOT-coreclr breaking-change Issue or PR that represents a breaking API or functional change over a prerelease. needs-breaking-change-doc-created Breaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet
Projects
None yet
4 participants