2011-11-21 72 views
0
String commClass = "ClassA"; 
Assembly objAssembly = Assembly.Load("DemoClassLibrary"); 
IA iFace = (IA)objAssembly.CreateInstance(commClass); 
iFace.run(); 

我在IFACE可变建立出错运行时对象

public interface IA 
{ 
    void run(); 
} 
public class ClassA : IA 
{ 
    string str = string.Empty; 

    public void run() 
    { 
     Console.WriteLine("{0}", DateTime.Now.Ticks); 
     Logger.Logger.CreateLog(DateTime.Now.Ticks.ToString()); 
    } 
} 

上面得到null是该命名空间DemoClassLibrary类声明

u能请帮助我..

thnx

回答

4

这可能是问题所在:

以上

是该命名空间DemoClassLibrary

你需要一个完全合格名传递给Assembly.CreateInstance类的声明,所以你可能想:

String commClass = "DemoClassLibrary.ClassA"; 
+0

简直太棒了爵士.. !!!! 谢谢 希望我有一天会变得像你一样:) – 1Mayur