public static Hashtable InvokeDll_Once(string searchPath, string dllFullName, string classFullName, string methodName, Type[] paraTypes, object[] paras) { AppDomain domain = null; Hashtable hashtable = null; string text = DateTime.Now.ToString("yyyyMMddHHmmssfff") + Guid.NewGuid().ToString().Replace("-", ""); try { domain = MainUtil.CreateShadowAppDomain(text, searchPath); RemoteUtil remoteUtil = MainUtil.CreateRemoteUtil(domain); hashtable = remoteUtil.InvokeDll(dllFullName, classFullName, methodName, paraTypes, paras); } catch (Exception ex) { hashtable = new Hashtable(); hashtable["Success"] = false; hashtable["Data"] = ex.ToString(); } finally { AppDomain.Unload(domain); try { Directory.Delete(AppDomain.CurrentDomain.BaseDirectory + "DynamicCache/" + text, true); } catch (Exception) { } } return(hashtable); }
/// <summary>只调用一次,不考虑连续调用的性能,这将会临时创建影子程序域调用结束后就卸载 /// </summary> /// <param name="searchPath">程序集的搜索路径</param> /// <param name="dllFullName">程序集的全称如:Demo2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</param> /// <param name="classFullName">执行类名</param> /// <param name="methodName">执行方法名</param> /// <param name="paraTypes">方法参数类型</param> /// <param name="paras">方法参数</param> /// <returns></returns> public static Hashtable InvokeDll_Once(string searchPath, string dllFullName, string classFullName, string methodName, Type[] paraTypes, object[] paras, string appconfigpath = null) { AppDomain domain = null; RemoteUtil remote = null; Hashtable ht = null; string tmpAppName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + Guid.NewGuid().ToString().Replace("-", ""); try { domain = CreateShadowAppDomain(tmpAppName, searchPath, appconfigpath); remote = CreateRemoteUtil(domain); //调用指定类的指定方法 ht = remote.InvokeDll(dllFullName, classFullName, methodName, paraTypes, paras); } catch (Exception ex) { ht = new Hashtable(); ht["Success"] = false; ht["Data"] = ex.ToString(); } finally { AppDomain.Unload(domain); try { Directory.Delete(AppDomain.CurrentDomain.BaseDirectory + "DynamicCache/" + tmpAppName, true); } catch (Exception) { } } return(ht); }
public static Hashtable InvokeDll_Direct(string typeName, string methodName, Type[] paraTypes, object[] paras) { Hashtable hashtable = null; try { RemoteUtil remoteUtil = new RemoteUtil(); hashtable = remoteUtil.InvokeDll(Type.GetType(typeName), methodName, paraTypes, paras); } catch (Exception ex) { hashtable = new Hashtable(); hashtable["Success"] = false; hashtable["Data"] = ex.ToString(); } return(hashtable); }