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

AppDomain.GetLoadedAssemblies() returns an array of all assemblies loaded in different AssemblyLoadContexts #46487

Closed
ValerCheck opened this issue Dec 31, 2020 · 3 comments
Labels
area-AssemblyLoader-coreclr untriaged New issue has not been triaged by the area owner

Comments

@ValerCheck
Copy link

In plugin-based architecture it can come to lazy load of some UI elements with the help of dotnet/wpf which brings us to SafeSecurityHelper.cs (which is also in dotnet/wpf) which in turn uses AppDomain.GetLoadedAssemblies() and looks for required dependencies.

If there is a common UI project which contains some xaml views to be re-used by plugins with the same UI, then on plugin load we create separate PluginLoadContexts and load each Common.UI instance into plugin's context. Then in runtime some time later we start creating Views from Common.UI, which then requires resolution of Common.UI.resources.dll and due to AppDomain.GetLoadedAssemblies() returns all of them, only the latest loaded Common.UI with the same version will be resolved.

Therefore, let say there are two plugins "Plugin1" and "Plugin2", each of them has a reference to "Common.UI" and after load start generating Views. Then, only one of them will be able to return correct view and that will be the latest loaded plugin. However, it is expected to load "Common.UI" for context related component.

I believe, at least ContextualReflection should be used here to solve it.

Configuration

.NET Core 3.1.101.
Windows 10, Version 1903, OS Build 18362.1256.
Architecture: x64

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-AssemblyLoader-coreclr untriaged New issue has not been triaged by the area owner labels Dec 31, 2020
@ghost
Copy link

ghost commented Dec 31, 2020

Tagging subscribers to this area: @vitek-karas, @agocke, @CoffeeFlux
See info in area-owners.md if you want to be subscribed.

Issue Details

In plugin-based architecture it can come to lazy load of some UI elements with the help of dotnet/wpf which brings us to SafeSecurityHelper.cs (which is also in dotnet/wpf) which in turn uses AppDomain.GetLoadedAssemblies() and looks for required dependencies.

If there is a common UI project which contains some xaml views to be re-used by plugins with the same UI, then on plugin load we create separate PluginLoadContexts and load each Common.UI instance into plugin's context. Then in runtime some time later we start creating Views from Common.UI, which then requires resolution of Common.UI.resources.dll and due to AppDomain.GetLoadedAssemblies() returns all of them, only the latest loaded Common.UI with the same version will be resolved.

Therefore, let say there are two plugins "Plugin1" and "Plugin2", each of them has a reference to "Common.UI" and after load start generating Views. Then, only one of them will be able to return correct view and that will be the latest loaded plugin. However, it is expected to load "Common.UI" for context related component.

I believe, at least ContextualReflection should be used here to solve it.

Configuration

.NET Core 3.1.101.
Windows 10, Version 1903, OS Build 18362.1256.
Architecture: x64

Author: ValerCheck
Assignees: -
Labels:

area-AssemblyLoader-coreclr, untriaged

Milestone: -

@jkotas
Copy link
Member

jkotas commented Dec 31, 2020

This is duplicate of dotnet/wpf#1700 . This issue needs to be fixed in WPF.

AppDomain.GetLoadedAssemblies() returns an array of all assemblies loaded in different AssemblyLoadContexts

This behavior is intentional. AppDomain.GetLoadedAssemblies in .NET Framework returned array of all assemblies loaded in different load contexts as well.

@jkotas jkotas closed this as completed Dec 31, 2020
@ValerCheck
Copy link
Author

@jkotas Thanks for pointing out.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-AssemblyLoader-coreclr untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

3 participants