Replacement for AppDomain.GetLoadedAssemblies() in .NET Core?
What you are looking for is broadly explained here. The author recommends creating a polyfill.
I am going to copy and paste in case the page goes missing.
public class AppDomain
{
public static AppDomain CurrentDomain { get; private set; }
static AppDomain()
{
CurrentDomain = new AppDomain();
}
public Assembly[] GetAssemblies()
{
var assemblies = new List<Assembly>();
var dependencies = DependencyContext.Default.RuntimeLibraries;
foreach (var library in dependencies)
{
if (IsCandidateCompilationLibrary(library))
{
var assembly = Assembly.Load(new AssemblyName(library.Name));
assemblies.Add(assembly);
}
}
return assemblies.ToArray();
}
private static bool IsCandidateCompilationLibrary(RuntimeLibrary compilationLibrary)
{
return compilationLibrary.Name == ("Specify")
|| compilationLibrary.Dependencies.Any(d => d.Name.StartsWith("Specify"));
}
}
Fixed this by upgrading my .netstandard
projects from 1.4
to 1.6
. The package Microsoft.Extensions.DependencyModel 1.1.2
now works.
Edit:
Using .netstandard2.0
removes the need for an AppDomain
polyfill class since it contains many more .NET APIs including System.AppDomain