To load an assembly and then get a list of all types:
Assembly assembly = Assembly.ReflectionOnlyLoadFrom("System.Core.dll"); Type[] types = assembly.GetTypes();
Unfortunately, this will throw an exception if any of the open types cannot be loaded, and sometimes this load failure cannot be avoided. In this case, however, the thrown exception contains a list of all types that were loaded successfully, and therefore we can simply do this:
Assembly assembly = Assembly.ReflectionOnlyLoadFrom("System.Core.dll"); Type[] types; try { types = assembly.GetTypes(); } catch (ReflectionTypeLoadException ex) { types = ex.Types; }
This will give you a list of all types, including interfaces, structures, enumerations, etc. (if you only need classes, you can filter this list).
source share