我在程序前面已经添加了using,引用了Child.dll的命名空间,但是还是只能找到MDIParentForm属性,不能找到ShowForm方法,麻烦两位给个例子好吗?

解决方案 »

  1.   

    try
    t.InvokeMember("ShowForm",flag,null,obj,null);--->
    m.InvokeMember(obj,null);
      

  2.   

    另外,楼主的方法效率不高
    如果要找这个方法
    可以这样
    foreach(Type t in ts)
    {
        MethodInfo m = t.GetMethod("ShowForm");
        if(m!=null)
        {
               object o = Activator.CreateInstance(t);
               m.InvokeMember(o,null);
         }
    }
      

  3.   

    你编译出来的DLL又没有改名 改过以后是不行的
      

  4.   

    你编译出来的DLL有没有改名 改过以后是不行的
      

  5.   

    试试
    Assembly a = Assembly.LoadFrom("Child.dll");
    Type ts= a.GetType();
    object dObj = Activator.CreateInstance(ts);
    Type[] tp=new Type[0];
    MethodInfo method = ts.GetMethod("ShowForm",tp);
    BindingFlags flag = BindingFlags.Public | BindingFlags.Instance;
    object returnValue = method.Invoke(dObj,flag,Type.DefaultBinder,null,null);
      

  6.   

    各位的方法都不行啊!
    MethodInfo method = ts.GetMethod("ShowForm",tp);
    执行后,method 为null。我已经添加了using,同时没有改名。如果我直接在程序中声明一个ChildForm变量,该变量的方法中可以找到ShowForm,并可以正确执行。但是,由于我希望程序灵活,不想写在程序中,所以请各位多出主意。
      

  7.   

    同意brightheroes(闭关|那一剑的风情)的看法.
      

  8.   

    参看http://community.csdn.net/Expert/topic/3183/3183458.xml
      

  9.   

    把你的ShowForm定义为static类型试试