Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting a list of types in an assembly that inherit from a specific interface
    primarykey
    data
    text
    <p><strong>Please read before marking as duplicate, already answered, on hold, or off topic.</strong></p> <p>First of all, I know there are SIMILAR question here, with very good answers. Unfortunately they do not answer my question.</p> <p>My goal: to create a list of all of the types within an assembly that inherit from a specific interface. This assembly may be located at a local path or a UNC path.</p> <p>My problem: First, I know how to load an assembly, both from a UNC and a local path, and I know how to use GetTypes(). Many of you may know that GetTypes() has it's own issue. Specifically, it will raise an exception if any of the Types inherit from another type that cannot be loaded. <a href="https://stackoverflow.com/questions/7889228/how-to-prevent-reflectiontypeloadexception-when-calling-assembly-gettypes">How to prevent ReflectionTypeLoadException when calling Assembly.GetTypes()</a> for instance. The problem is, I don't need to load any of the dependencies. I only need to see if a type declared in the assembly inherits from an other specific type.</p> <p>some code as an example. This is just the first step, to retrieve the types in the assembly:</p> <pre><code>Assembly asm = Assembly.Load(File.ReadAllBytes(assemblyPath)); Type[] myTypes = GetLoadableTypes(asm); public static Type[] GetLoadableTypes(Assembly assembly) { // TODO: Argument validation try { return assembly.GetTypes(); } catch (ReflectionTypeLoadException e) { return e.Types.Where(t =&gt; t != null); } } </code></pre> <p>If any of the Types inside of the assembly inherit from a type that cannot be loaded, a ReflectionTypeLoadException exception will be thrown and they will show up as null inside of e.Types, so there is still no information on them. So I guess I can't use GetTypes still.</p> <p>For completeness, here is a reference to my original question. <a href="https://stackoverflow.com/questions/20251600/how-to-get-type-information-when-reflectiontypeloadexception-is-thrown-from-asse">How to get Type information when ReflectionTypeLoadException is thrown from Assembly.GetType()</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload