class ProxyObject : MarshalByRefObject { Assembly assembly = null; public void LoadAssembly(string choice) { //获取dll所在路径 string dllPath = Config.GetValueByKey(choice, "dllPath"); //获取dll名称/exe名称 string dllName = Config.GetValueByKey(choice, "dllName"); assembly = Assembly.LoadFile(AppDomain.CurrentDomain.BaseDirectory + dllPath + dllName); } }
上边我的代理类,然后是在新的程序域中创建对象
ad = AppDomain.CreateDomain("DLL Unload " + choiceOpiton); ProxyObject instance = (ProxyObject)ad.CreateInstanceFromAndUnwrap("dll全路径","Proxy所在类名");
然后就提示错误“无法将透明代理强制转换为类型ProxyObject”
求救~