第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Assembly卸載DLL有比較完美的解決方案嗎

Assembly卸載DLL有比較完美的解決方案嗎

紅顏莎娜 2018-12-06 11:58:37
最近我使用vs2005做了一個addins在制作的過程中使用Assembly動態(tài)加載DLL,其他的地方需要實現(xiàn)刪除DLL的操作,因此需要能夠?qū)崿F(xiàn)卸載Assembly動態(tài)加載DLL,不知道各位有沒有什么好的解決方案。大多數(shù)都說用AppDomain來實現(xiàn),試驗過很多,都存在這樣或者那樣的問題,大家有沒有一個比較完美的解決方案啊。 public Assembly LoadAssembly(string filePath) { Assembly asm = null; if (this.copyToMem) { //先將插件拷貝到內(nèi)存緩沖 byte[] addinStream = null; if (FileHelper.ReadFileToBuff(filePath, out addinStream)) { asm = Assembly.Load(addinStream); //加載內(nèi)存中的Dll } } else { asm = Assembly.LoadFrom(filePath); } return asm; } ? 使用過上面的這種方式加載DLL,可是因為需要加載附加的DLL,還是失敗。
查看完整描述

1 回答

?
偶然的你

TA貢獻(xiàn)1841條經(jīng)驗 獲得超3個贊

請參考如下代碼片段:

?public DynamicAssembly()
??????? {
??????????? PermissionSet perSet = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.Unrestricted);
??????????? AppDomainSetup objSetup = new AppDomainSetup();
??????????? objSetup.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;
??????????? _objAppDomain = AppDomain.CreateDomain("MyAppDomain", null, objSetup, perSet, null);
??????? }

?

?public void InitCall()
??????? {
??????????? string strErrorMsg = string.Empty;
??????????? RemoteLoaderFactory factory = (RemoteLoaderFactory)_objAppDomain.CreateInstance("UIT.DynamicExpression.RemoteAccess", "UIT.DynamicExpression.RemoteAccess.RemoteLoaderFactory").Unwrap();

??????????? // with help of factory, create a real 'LiveClass' instance
??????????? _object = factory.Create("UIT.DynamicalExpressionBin.dll", "UIT.DynamicExpression.Eval", null);

??????????? if (_object == null)
??????????? {
??????????????? strErrorMsg = "Error: " + "Couldn't load class.";
??????????????? Trace.WriteLine(strErrorMsg);
??????????? }
??????? }

其中RemoteFactory類代碼如下:

?public class RemoteLoaderFactory : MarshalByRefObject
??? {
??????? private const BindingFlags bfi = BindingFlags.Instance | BindingFlags.Public | BindingFlags.CreateInstance;


??????? public RemoteLoaderFactory() { }


??????? public IRemoteInterface Create(string assemblyFile, string typeName, object[] constructArgs)
??????? {
??????????? return (IRemoteInterface)Activator.CreateInstanceFrom(
???????????????????? assemblyFile, typeName, false, bfi, null, constructArgs,
???????????????????? null, null, null).Unwrap();
??????? }
??? }

查看完整回答
反對 回復(fù) 2019-01-21
  • 1 回答
  • 0 關(guān)注
  • 405 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號