I’m completely new to loading in libraries like this, but here’s where I stand:
I have a homemade DLL file it’s about as simple as it gets, the class itself and a method. In the home program that loads this library, I have:
Assembly testDLL = Assembly.LoadFile("C:\\dll\\test.dll");
From here, I’m kind of stuck. As far as I know, it’s loading it correctly because it gives me errors when I change the name.
What do I do from here? How exactly do I load the class & methods within it?
Thanks.
Use
Assembly.GetTypes()to get a collection of all the types, orAssembly.GetType(name)to get a particular type.You can then create an instance of the type with a parameterless constructor using
Activator.CreateInstance(type)or get the constructors usingType.GetConstructorsand invoke them to create instances.Likewise you can get methods with
Type.GetMethods()etc.Basically, once you’ve got a type there are loads of things you can do – look at the member list for more information. If you get stuck trying to perform a particular task (generics can be tricky) just ask a specific question an I’m sure we’ll be able to help.