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

Developers can create scopes to support load/unload scenarios because AssemblyLoadContext is supported throughout .NET #43544

Open
1 task
Tracked by #44314
samsp-msft opened this issue Oct 16, 2020 · 6 comments
Assignees
Labels
area-Meta Priority:2 Work that is important, but not critical for the release Team:Runtime User Story A single user-facing feature. Can be grouped under an epic.
Milestone

Comments

@samsp-msft
Copy link
Member

The assembly load context has been rather successful in solving a large set of customer problems. The most prominent one is the so called “plugin” model where the application (host) loads other components to augment its functionality in some way. Such components are typically loaded into separate load contexts to avoid dependency collisions. Additionally, in some apps it’s also desirable to be able to eventually unload such components either to free resources or to enable update of the component.

Producing such applications has proven rather challenging in the current state of .NET Core because there are certain parts of the frameworks produces by us which are not compatible with multiple load contexts and/or unload ability.
We should drive the frameworks we own to fix these issues so that customer’s code doesn’t have to handle issues in frameworks they rely on. We should focus this effort on certain application types first to prioritize the work. We’ve seen feedback on mainly ASP.NET and WPF applications. There might be overlap with the “faster inner loop” effort which would affect the prioritization as well.

The work can be split into two parts (and prioritized differently):

  • Given feature works correctly in presence of secondary load context – for example XamlParser has problems when used with assemblies in non-default load context. Similarly, ASP.NET’s hosting code also doesn’t work well in such a scenario. It might be possible to use static analyzers to detect some of the problems in this area.
  • Usage of a given feature doesn’t prevent secondary load context from unloading correctly – for example TypeConverter holds onto all types which were used with it, and thus prevents unloading of such types. Static analyzers are probably not going to help in this area.

In both cases an important part of the work should be a general approach to testing – for example reuse existing test assets but run them under different conditions and providing customer guidance for first & third parties.

Work Items

  • TBD
@samsp-msft samsp-msft added area-Meta User Story A single user-facing feature. Can be grouped under an epic. labels Oct 16, 2020
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged New issue has not been triaged by the area owner label Oct 16, 2020
@Pilchie
Copy link
Member

Pilchie commented Oct 19, 2020

dotnet/aspnetcore#21159 is a related workitem.

@samsp-msft samsp-msft changed the title User Story: Support assembly load context throughout the product User Story: Assembly load context is supported throughout .NET so developers can create scopes to support load/unload scenarios Oct 22, 2020
@cathysull cathysull added the Priority:2 Work that is important, but not critical for the release label Oct 30, 2020
@srxqds
Copy link
Contributor

srxqds commented Nov 5, 2020

excited,thank you.
the monovm runtime is not full supported.
we hope you can keep more focus on it.
we are waiting for it everyday.
thank you.

@danmoseley danmoseley changed the title User Story: Assembly load context is supported throughout .NET so developers can create scopes to support load/unload scenarios Developers can create scopes to support load/unload scenarios because AssemblyLoadContext is supported throughout .NET Nov 29, 2020
@danmoseley
Copy link
Member

@jeffschwMSFT this seems primarily runtime work. Is there a better epic to parent it under than the libraries one?

@jeffschwMSFT
Copy link
Member

I don't have a strong feeling about where it would parent. It was in the theme of developer experience and hence why it ended up here. At this point there is no specific ask but once the dev inner loop work is settled it could become more important. So it could either become bottoms up or parent under dev inner loop.

@danmoseley
Copy link
Member

@stephentoub when he's back can perhaps help clarify whether this is necessary for dev inner loop.

@govert
Copy link
Contributor

govert commented Feb 27, 2021

I am loading the runtime and a managed assembly from native code using the hostfxr hosting interfaces. I find that my managed assembly is loaded into a new IsolatedComponentLoadContext as expected. I then create a new CustomAssemblyLoadContext of my own, into which further code is loaded. I can never unload the library that contains the initial managed entry point as it will be loaded into the IsolatedComponentLoadContext , and this type is not created as IsCollectible.

I want to suggest as part of this issue that the hostfxr gets some mechanism to make a collectible managed extension, loaded from the native host interfaces. (I am not trying to unload the runtime from the process, just my own native & managed libraries, for example to update and reload it.) Ideally, I want my (collectible) CustomAssemblyLoadContext to be instantiated as part of my initial managed code load, and then have some mechanism to (attempt to) unload this collectible ALC from the native hostfxr side.

I'm not quite there yet, but I think I would also like a way to know (from the native hostfxr side) when the unload attempt is complete, and whether it was successful. Maybe some callback would work for this.

Under the .NET Framework, such unloading works through the AppDomain support and ICorRuntimeHost->UnloadDomain(...)

@jeffschwMSFT jeffschwMSFT removed the untriaged New issue has not been triaged by the area owner label Jul 6, 2021
@vitek-karas vitek-karas modified the milestones: 6.0.0, Future Aug 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Meta Priority:2 Work that is important, but not critical for the release Team:Runtime User Story A single user-facing feature. Can be grouped under an epic.
Projects
No open projects
Development

No branches or pull requests

10 participants