9
votes

It's easy to get list of all loaded assemblies in .NET:

AppDomain.CurrentDomain.GetAssemblies()

But I can't find a way to do this in PCL (portable class library) code? Any suggestions?

1
AppDomain just isn't portable. Entirely missing in Store and Phone8, very limited capabilities in the CoreCLR. So it is omitted in PCL.Hans Passant
I know that AppDomain isn't portable. So there is no way to get all loaded assemblies in PCL?Andrey

1 Answers

-2
votes

Not sure if Deployment.Current.Parts is available in PCL, but I use:

public static List<Assembly> GetAssemblies()
{
    List<Assembly> assemblies = new List<Assembly>();

    foreach (var assemblyPart in Deployment.Current.Parts)
    {
        StreamResourceInfo sri = Application.GetResourceStream(new Uri(assemblyPart.Source, UriKind.Relative));
        Assembly a = new AssemblyPart().Load(sri.Stream);

        if (a != null)
            assemblies.Add(a);
    }

    return assemblies;   
}