好像只能接收object类型,你可以把你的自定义类型转换object再传进去

解决方案 »

  1.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Net;
    using System.IO;
    using System.Threading;
    using System.Management;
    using System.Runtime.InteropServices;
    using System.Collections;
    using System.Reflection;namespace WindowsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private struct MyInfo
            {
                public string name;
                public int id;
            }        private void ShowInfo(MyInfo info)
            {
                MessageBox.Show(info.id.ToString() + "  " + info.name);
            }        private void button1_Click(object sender, EventArgs e)
            {
                Type t = this.GetType();
                if (t != null)
                {
                    MethodInfo m = t.GetMethod("ShowInfo", BindingFlags.NonPublic | BindingFlags.Instance);
                    if (m != null)
                    {
                        MyInfo info;
                        info.id = 100;
                        info.name = "sfsfsf";                    // 这里只接受object[]的类型,但可以把MyInfo转为object[]
                        object[] objs = new object[1];
                        objs[0] = info;
                        m.Invoke(this, objs);
                    }
                }
            }
        }
    }
      

  2.   

    谢谢楼上的回答 我把程序贴出来
    AppdomainTest.dllnamespace AppdomainTest
    {
        class Program
        {
            static void Main(string[] args)
            {
                try
                {
                    string strPath = @"D:\My Documents\Visual Studio 2008\Projects\AppdomainTestClass\AppdomainTestClass\bin\Debug\AppdomainTestClass.dll";
                    string strName2 = @"AppdomainTestClass.Class1";                AppDomain domain = AppDomain.CreateDomain("appdomain test");
                    TestQueue _TestQueue = new TestQueue();               ObjectHandle oh =
                        domain.CreateInstanceFrom(strPath, strName2, false, System.Reflection.BindingFlags.CreateInstance, null, new object[] { _TestQueue }, null, null, null);//这里会抛出MissingMethodException异常
                    Console.WriteLine("Success!");            }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                finally
                {
                    Console.ReadLine();
                }
            }
        }
    }
    AppdomainTestClass.dllnamespace AppdomainTest
    {
        class Program
        {
            static void Main(string[] args)
            {
                try
                {
                    string strPath = @"D:\My Documents\Visual Studio 2008\Projects\AppdomainTestClass\AppdomainTestClass\bin\Debug\AppdomainTestClass.dll";
                    string strName2 = @"AppdomainTestClass.Class1";                AppDomain domain = AppDomain.CreateDomain("appdomain test");
                    TestQueue _TestQueue = new TestQueue();
                    Queue _Queue = new Queue();               ObjectHandle oh =
                        domain.CreateInstanceFrom(strPath, strName2, false, System.Reflection.BindingFlags.CreateInstance, null, new object[] { _TestQueue }, null, null, null);
                    Console.WriteLine("Success!");            }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                finally
                {
                    Console.ReadLine();
                }
            }
        }
    }
      

  3.   

    不好意思  以上的AppdomainTestClass.dll贴错了  重贴 
    AppdomainTestClass.dllnamespace AppdomainTestClass
    {
        public class Class1:MarshalByRefObject
        {
            public Class1(){}
            public Class1(TestQueue Queue) { }
        }    public class TestQueue:MarshalByRefObject
        {
            public TestQueue() { }
        }
    }
      

  4.   

    ObjectHandle oh =
                        domain.CreateInstanceFrom(strPath, strName2, false, System.Reflection.BindingFlags.CreateInstance, null, new object[] { _TestQueue }, null, null, null);会抛出MissingMethodException异常如果Class1的构造函数参数改成object就没问题
    还有如果Class1的构造函数参数改成string,并且CreateInstanceFrom方法里也改成将string类型传进去也不会有问题
    就是自定义的有问题 为什么
      

  5.   

    MSDN上对AppDomain类的CreateInstanceFrom方法的object[]参数说的明白:
    object[]包含一个或多个可以参与激活的属性的数组。通常是包含单个 UrlAttribute 对象的数组。UrlAttribute 指定激活远程对象所需的 URL。不是你那用法