Tutorial :load assemby at runtime



Question:

I load my assembly at runtime (but this assemby is not refenced by the project)

Assembly a = Assembly.LoadFile(@"fulpath\assName.dll");  

after that I want to use one class from this dll by reflection

obj = Activator.CreateInstance(Type.GetType("assemblyqualifiedname"));  mi = obj.GetType().GetMethod("methodname");  mi.Invoke(obj, null);  

unfortunately , bull returns from Type.GetType("assemblyqualifiedname");

I dont understand , why I must to add reference od dll to project ?

Load assembly should be enough , but it doesnt .

thanks ...


Solution:1

When you load an assembly manually, you should use its getType method. Type.getType will use the calling assembly and its reference to search for the type. a.GetType will find the type, because it looks inside the loaded assembly.


Solution:2

This may also help you: Problems loading assembly dependencies dynamically at run-time


Solution:3

What is your objection to adding a reference to the DLL in the project?


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »