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

[loader] Set domain->entry_assembly earlier in startup #31814

Merged
merged 1 commit into from
Feb 7, 2020

Conversation

CoffeeFlux
Copy link
Contributor

When locating AppContext.BaseDirectory on netcore, if APP_CONTEXT_BASE_DIRECTORY is not set we call into the runtime for a fallback location, which checks domain->entry_assembly. On legacy this is fine because we set that property in prepare_thread_to_exec_main, but on netcore the new managed assembly loading algorithm will call into managed and check the property before that function is run, which will result in AppContext.BaseDirectory returning an empty string. The solution is to set entry_assembly a bit earlier in initialization. This is the appropriate location because it's what embedding API users will call to run an assembly.

In the process, I got rid of some code that would bypass the usual lookup algorithm unnecessarily.

Fixes #31800

When locating AppContext.BaseDirectory on netcore, if APP_CONTEXT_BASE_DIRECTORY is not set we call into the runtime for a fallback location, which checks domain->entry_assembly. On legacy this is fine because we set that property in `prepare_thread_to_exec_main`, but on netcore the new managed assembly loading algorithm will call into managed and check the property before that function is run, which will result in AppContext.BaseDirectory returning an empty string. The solution is to set entry_assembly a bit earlier in initialization. This is the appropriate location because it's what embedding API users will call to run an assembly.

In the process, remove some code that would bypass the usual lookup algorithm unnecessarily.
@CoffeeFlux
Copy link
Contributor Author

Rebased on top of Egor's work; confirmed that it can run the CoreCLR tests without issue.

I'm still somewhat hesitant on whether this is the right place to set this, but after sleeping on it I think it's okay with an in-code comment. Will merge once CI is green.

@CoffeeFlux CoffeeFlux merged commit 8e58d13 into dotnet:master Feb 7, 2020
@ghost ghost added the will_lock_this label Dec 6, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Jan 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[mono] AppContext.BaseDirectory is empty in some cases
3 participants