Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get list of loaded Assemblies on UAP10 platform

On "normal" .NET assemblies targeting .NET Framework 4, I can use AppDomain.CurrentDomain.GetAssemblies() to get a list of all loaded assemblies.

How to do this on a Windows Universal App or on a CoreCLR application?

like image 792
Carsten Schütte Avatar asked Jan 07 '23 14:01

Carsten Schütte


2 Answers

One way to kinda do what you want is to get the DLLs/assemblies which is located in the folder in which your app is installed (which one can assume in some cases is being used/loaded in your app).

    public static async Task<List<Assembly>> GetAssemblyList()
    {
        List<Assembly> assemblies = new List<Assembly>();

        var files = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFilesAsync();
        if (files == null)
            return assemblies;

        foreach (var file in files.Where(file => file.FileType == ".dll" || file.FileType == ".exe"))
        {
            try
            {
                assemblies.Add(Assembly.Load(new AssemblyName(file.DisplayName)));
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }

        }

        return assemblies;
     }

Then to loop through them you could do:

foreach (var assembly in GetAssemblyList().Result)
{
   //Do something with it
}

Credits to this reddit thread/user.

like image 96
Whyser Avatar answered Jan 14 '23 23:01

Whyser


How to do this on a Windows Universal App or on a CoreCLR application?

No, you can’t. Comparing with the Full.NET, the .NET for UWP only provides limited-level reflection functions. In .NET for UWP, you can only get the assembly information by using the code below.

var assembly = this.GetType().GetTypeInfo().Assembly;
like image 35
Jeffrey Chen Avatar answered Jan 15 '23 01:01

Jeffrey Chen