Skip to content

Instantly share code, notes, and snippets.

@tsmoreland
Created March 13, 2021 08:44
Show Gist options
  • Save tsmoreland/69e2c81af4df830eca2b8dce54faab2f to your computer and use it in GitHub Desktop.
Save tsmoreland/69e2c81af4df830eca2b8dce54faab2f to your computer and use it in GitHub Desktop.
C# Force get all types in AppDomain including referenced assemblies

Example of Getting all types from AppDomain

var assemblies = AppDomain.Current.GetAssemblies().ToList(); // to list is needed because we're about to interate and add
var referencedAssemblies = assemblies
  .SelectMany(asm => asm.GetReferencedAssemblies())
  .Select(asmName =>
  {
    try
    { 
      return Assembly.Load(asmName);
    }
    catch (Exception)
    {
      return (Assembly?)null;
    }
  })
  .Where(asm => asm != null)
  .ToArray();
assemblies.AddRange(referencedAssemblies);

var types = assemblies.SelectMany(asm => asm.GetTypes());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment