Get list of loaded Assemblies on UAP10 platform

后端 未结 3 672
Happy的楠姐
Happy的楠姐 2020-12-10 20:02

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

How

3条回答
  •  一向
    一向 (楼主)
    2020-12-10 20:48

    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> GetAssemblyList()
        {
            List assemblies = new List();
    
            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.

提交回复
热议问题