我正在嘗試將加載到控制檯應用程序的DLL中,然後卸載它並完全刪除文件。我遇到的問題是,在自己的AppDomain中加載dll的行爲會在Parent AppDomain中創建一個引用,從而不允許我銷燬該dll文件,除非我完全關閉該程序。任何想法使這個代碼工作?在新AppDomain中加載程序集而不將其加載到父AppDomain中
string fileLocation = @"C:\Collector.dll";
AppDomain domain = AppDomain.CreateDomain(fileLocation);
domain.Load(@"Services.Collector");
AppDomain.Unload(domain);
BTW我自己也嘗試這個代碼沒有運氣或者
string fileLocation = @"C:\Collector.dll";
byte[] assemblyFileBuffer = File.ReadAllBytes(fileLocation);
AppDomainSetup domainSetup = new AppDomainSetup();
domainSetup.ApplicationBase = Environment.CurrentDirectory;
domainSetup.ShadowCopyFiles = "true";
domainSetup.CachePath = Environment.CurrentDirectory;
AppDomain tempAppDomain = AppDomain.CreateDomain("Services.Collector", AppDomain.CurrentDomain.Evidence, domainSetup);
//Load up the temp assembly and do stuff
Assembly projectAssembly = tempAppDomain.Load(assemblyFileBuffer);
//Then I'm trying to clean up
AppDomain.Unload(tempAppDomain);
tempAppDomain = null;
File.Delete(fileLocation);
這個鏈接是死了! – ZioN
請您提供代碼 – ZioN
新鏈接:https://bmark.us/bmark/readable/9503538d6bab80 – user1