简体   繁体   中英

Loading and unloading of same dll with different version using appdomain

I am having a windows application in which I am loading and unloading the dll multiple times at run time and it works fine when i am using the same version dll. Problem arises when i try to load the same dll with different version at run time. For example: I loaded the dll "version1" and unloaded it and then i tried to load the same dll with different version say "version2", its not allowing me to load.

Please find below code for loading/unloading:

Loading Code:

if (this.libraryDomain != null)
     {
        AppDomain.Unload(this.libraryDomain);
     }

     // Re-create the AppDomain and create an instance of the Preview Bridge Module
     this.libraryDomain = System.AppDomain.CreateDomain("PreviewLibraryDomain");
     PreviewLibraryLoader previewLibraryLoader = this._previewLibraryDomain.CreateInstanceAndUnwrap(
                                                    "Preview.Library.Interface", "Preview.Library.Interface.PreviewLibraryLoader") as PreviewLibLoader;

     this._bridgeModule = previewLibraryLoader.LoadPreviewLibrary(assemblyPath);

Unloading Code:

if (this.libraryDomain != null)
        {

           AppDomain.Unload(this.libraryDomain);
           this.libraryDomain = null;
        }

You must read this question

Hot Unload/Reload of a DLL used by an Application

Once an assembly has been loaded into an AppDomain, it cannot be unloaded. You can test it trying to delete version1.dll. The dll is linked with the application, however it is unloaded.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM