SuperJMN
SuperJMN

Reputation: 13992

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.

Upvotes: 6

Views: 800

Answers (1)

igorc
igorc

Reputation: 2034

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).

Upvotes: 5

Related Questions