Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalence for AppDomain.GetAssemblies() in UWP?

I'm going crazy looking for it!

I was close to the answer in this post, but there is no DependencyContext.Default in that package.

like image 473
SuperJMN Avatar asked Jun 28 '17 21:06

SuperJMN


People also ask

What is AppDomain in C#?

The AppDomain class implements a set of events that enable applications to respond when an assembly is loaded, when an application domain will be unloaded, or when an unhandled exception is thrown.

What is AppDomain CurrentDomain?

The CurrentDomain property is used to obtain an AppDomain object that represents the current application domain. The FriendlyName property provides the name of the current application domain, which is then displayed at the command line.

What is AssemblyName in C#?

The assembly cache manager uses AssemblyName objects for binding and retrieving information about an assembly. An assembly's identity consists of a simple name, a version number, a cryptographic key pair, and supported culture. The simple name is unencrypted name, as distinguished from the strong name.


1 Answers

Nothing equivalent - not supported in UWP/PCL.

Not supported in PCL because the library does not know of all the assemblies, until they are built and packed, not entirely clear why this is not supported for UWP.

This is the closest thing you can get (this will enumerate all the assemblies in your package):

private async Task<IEnumerable<Assembly>> GetAssemblyListAsync()
{
   var folder = Windows.ApplicationModel.Package.Current.InstalledLocation;

   List<Assembly> assemblies = new List<Assembly>();
   foreach (Windows.Storage.StorageFile file in await folder.GetFilesAsync())
   {
        if (file.FileType == ".dll" || file.FileType == ".exe")
        {
           AssemblyName name = new AssemblyName() { 
                                         Name = Path.GetFileNameWithoutExtension(file.Name) };
           Assembly asm = Assembly.Load(name);
           assemblies.Add(asm);
        }
   }

   return assemblies;
}

some old discussion on this (nothing changed since then).

like image 139
igorc Avatar answered Oct 20 '22 03:10

igorc