How can I get a list of types from a DLL in C #?

I would like to specify a C # application in a DLL and get a list of types defined in this DLL. The fact that I still look directly at the surface, but gives the error indicated below.

using System.Reflection; ... static void Main(string[] args) { Assembly SampleAssembly; SampleAssembly = Assembly.LoadFrom("C:\\MyAssembly.dll"); //error happens here foreach (Type tp in SampleAssembly.GetTypes()) { Console.WriteLine(tp.Name); } } /* This will give me: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. I wish it would give me something like this: MyClass1 MyClass2 MyClass3 */ 
+4
source share
2 answers

Use ReflectionOnlyLoad instead of direct loading to prevent any script from executing any code in the target assembly.

+5
source

A ReflectionTypeLoadException is thrown because one of your types throws an exception during static initialization. This can happen if the method / property / field signatures depend on a type that is not available. I recommend that you catch this exception and check the contents of the LoaderExceptions property of the exception, as suggested.

+2
source

All Articles