偶就是想动态我那个dll里滴方法
那个dll里的命名空间是ModuleFun;
里面有两个类,一个是Module 对象 一个是 ModuleContent 类,我要调用的方法都在这个类里,用Module初始化他
ModuleFun.Module module = new ModuleFun.Module();
ModuleContent content = new ModuleContent(module);
Type type = content.GetType();
object o = Activator.CreateInstance(type,module);
MethodInfo mi = type.GetMethod("DayTeam");//这里是调用没有参数的的DayTeam方法
string result = (string)mi.Invoke(o, null);
Response.Write(result);
上面代码报错。。晕死咯还有个问题
如果DayTeam这个方法带参数咋办捏?

解决方案 »

  1.   


               Assembly ass = Assembly.LoadFrom(@"F:\txt\Solution1\psp\bin\Debug\psp.dll");
               Type type = ass.GetTypes()[0];
               MethodInfo mi = type.GetMethod("Showtxt");
               object obj = ass.CreateInstance(type.ToString());
               object[] o = new object[] { "b2b" };
               string mystr =(string)mi.Invoke(obj,o);
               Response.Write(mystr);
      

  2.   

    ModuleContent 类有个构造函数,接收Module对象来,实例化哇,怎么弄哦?
      

  3.   

    1.构造函数参数传入
     object o = Activator.CreateInstance(type, new object[] {module}); 2.方法参数传入
      object[] o = new object[] { "b2b" };
          string mystr =(string)mi.Invoke(obj,o);
      

  4.   

      ModuleFun.Module module = new ModuleFun.Module();
            Assembly ass = Assembly.LoadFrom(Server.MapPath("Bin") + "//" + "ModileFun.dll");
            Type type = ass.GetTypes()[0];
            MethodInfo mi = type.GetMethod("Test");
            object obj = ass.CreateInstance(type.ToString());
            object[] o = new object[] {module};
            string mystr = (string)mi.Invoke(obj,o);
            Response.Write(mystr);
    改成这样提示:未找到类型“ModuleFun.ModuleContent”上的构造函数。 
      

  5.   

      ModuleFun.Module module = new ModuleFun.Module();
      ModuleContent content = new ModuleContent(module);
      Type type = content.GetType();
      object o = Activator.CreateInstance(type, new object[] { module });
       MethodInfo mi = type.GetMethod("Test");//这里是调用没有参数的的DayTeam方法 
       //object[] o = new object[] { "b2b" };
        object mystr = mi.Invoke(o, null);
      

  6.   

    为了mm,活出去了..
    using System;
    using System.Collections.Generic;
    using System.Reflection;
    public class MyClass
    {
     public static void Main()
    {
           Person  p = new  Person();  
           Type type = p.GetType();    // or Type type = Type.GetType("ModuleFun.Module,ModuleFun");
           object o = Activator.CreateInstance(type, new object[] { "miaomiao"}); 
           MethodInfo mi = type.GetMethod("SayHello");
           object mystr = mi.Invoke(o, null);
           Console.WriteLine(mystr.ToString());
    }
     }
    public class  Person
    {
    private  string username;
    public Person(){}
    public  Person(string name){
     username = name;
    }
    public string SayHello(){
      return  "hello,"+username;
    }
    }
      

  7.   

    你再看看我说滴是
    dll里的命名空间ModuleFun下有两个类
    一个是Module
    一个是ModuleContent
    ModuleContent构造函数需要一个Module对象初始化
      

  8.   

    Type Moduletype = Type.GetType("ModuleFun.Module,ModuleFun"); 
    Type ModuleContenttype = Type.GetType("ModuleFun.ModuleContent,ModuleFun"); object moduleContent = Activator.CreateInstance(ModuleContenttype,null); 
    object module = Activator.CreateInstance(Moduletype,moduleContent); MethodInfo mi = Moduletype.GetMethod("DayTeam");string result = (string)mi.Invoke(module, null); 
      

  9.   

     ModuleFun.Module module = new ModuleFun.Module();
            ModuleContent content = new ModuleContent(module);
            Type type = content.GetType();
            object o = Activator.CreateInstance(type, new object[] { module });
            MethodInfo mi = type.GetMethod("Test");
            object mystr = mi.Invoke(o, null);
            Response.Write(mystr.ToString());
    不就是这个意思么 不可以 哎
      

  10.   

    http://www.cartoonb2b.cn/ref.rar传上去了。
      

  11.   

    Invoke() 这个方法在 .net 1.1 里用什么方法代替 ?