c# - How to initialize one class from a library? -


I have some classes in class library (separate assembly). I have referred it in my project and I I want to start a specific class. I only know his name, all classes apply an interface. And here comes the problem.

My code so far:

  using MyLibrary; ... IMyInterface dll = Activator.CreateInstance ("MyLibrary", "MyLibrary.NameOfClass") as IMyInterface;  

But DLL is always zero. Any ideas?

Thanks

UPDATE

I remove the reference to the library and rewrite that code:

  assembly A = assembly Load ("MyLibrary"); Type type = a.GetType ("MyLibrary.SKClass"); IMyInterface obj = Activator.CreativeInstance (type) as IMyInterface;  

But obj is empty.

If I check library types with a.GetExportedTypes (), then if there is SK Class there, why is this code still returning empty?

assembly = assembly.LoadFile (@ "full \ path \ to.dll");

var type = assemblyGateType ("typed .namespace");

var object = catalyst. Create Instances (Type);


Comments