Balraj Singh
Balraj Singh

Reputation: 3471

Get all list of assemblies in Windows 8 C#?

What is equivalent of Assembly a in AppDomain.CurrentDomain.GetAssemblies() in Windows 8.

My object is to load all template control from different projects in Windows 8 project. So I am trying to first load all the assemblies in the current Solution and then get the controls from it?

Upvotes: 0

Views: 1347

Answers (1)

Damir Arh
Damir Arh

Reputation: 17865

There is no exact equivalent available in Windows Store apps for a good reason: these apps are distributed as packages and there is no way to extend them with plugins, i.e. you know exactly which assemblies an app is comprised of, when you deploy it.

To get the assemblies distributed (included in your project), you will first need to reference them from your main project. Then you could use the following code to iterate through all assemblies in the package installed location, load them and iterate through their types (you should add some exception handling before you use this code in production):

var folder = Package.Current.InstalledLocation;
foreach (var file in await folder.GetFilesAsync())
{
    if (file.FileType == ".dll")
    {
        var assemblyName = new AssemblyName(file.DisplayName);
        var assembly = Assembly.Load(assemblyName);
        foreach (var type in assembly.ExportedTypes)
        {
            // check type and do something with it
        }
    }
}

In the inner loop you could check for some properties of the type to recognize which ones of them are controls that you are seeking and do with them whatever you need to.

Upvotes: 2

Related Questions