C#使用域进行加载dll获取方法名称被占用

 public class MyMarshalByRefObject : MarshalByRefObject
    {
        public string dll_path = string.Empty;
        Assembly assembly = null;

        public void Load_Dll()
        {
            assembly = Assembly.LoadFile(dll_path);
        }
        /// 
        /// 运行规则
        /// 
        /// 空间
        /// 函数名
        /// 参数
        /// 参数对应类型
        public void RunCommand(string strtype, string MethodName, object[] parameters = null, Type[] types = null )
        {
            if (MethodName != "")
            {
                //创建类实例
                object tdll = assembly.CreateInstance(strtype);
                if (types == null)
                {
                    types = new Type[] { };
                }
                //获取方法
                MethodInfo m = tdll.GetType().GetMethod(MethodName, types);
                //委托调用
                object obj = m.Invoke(tdll, parameters);
                string message = "函数名:" + MethodName + "\n";
                if (obj != null)
                {
                    message += "结果:" + obj.ToString();
                }
                else
                {
                    message += "结果:void";
                }
                Log.WriteLine(message, "函数结果");
                return;
            }
            else
            {
                Log.WriteLine("规则名不能为空!", "函数调用错误");
            }

        }
        internal MethodInfo[] GetMethodNames(string strtype)
        {
            object tdll = assembly.CreateInstance(strtype);
            //重新生成报错dll被占用
            MethodInfo[] methodInfos = tdll.GetType().GetMethods(BindingFlags.Public|BindingFlags.Instance );
            return methodInfos;
        }
    }
GetMethodNames调用这个函数之后再次重新编译dll 还是报错dll被占用 暂时放弃这个方法不用

你可能感兴趣的:(错误日志(待研究))