Skip to content

Instantly share code, notes, and snippets.

@jcansdale
Last active August 14, 2016 21:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcansdale/f0c2f70c2dc8094e4fb8eaba6506a550 to your computer and use it in GitHub Desktop.
Save jcansdale/f0c2f70c2dc8094e4fb8eaba6506a550 to your computer and use it in GitHub Desktop.
.NET Core implementation of AppDomain.GetAssemblies()
public Assembly[] GetAssemblies()
{
var assemblies = new List<Assembly>();
foreach(ProcessModule module in Process.GetCurrentProcess().Modules)
{
try
{
var assemblyName = AssemblyLoadContext.GetAssemblyName(module.FileName);
var assembly = Assembly.Load(assemblyName);
assemblies.Add(assembly);
}
catch(BadImageFormatException)
{
// ignore native modules
}
}
return assemblies.ToArray();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment