Thursday, August 03, 2006

Keeping Dynamically Loaded Plugin Assemblies unlocked in ASP.Net

I have written a plugin system for an application. The system basically searches a plugin directory for assemblies containing types implementing the IPlugin interface. To do this it needs to load the assemblies at runtime. The problem I had with this was that it locked the files once they were loaded. If I then compiled a new version it failed to copy the assembly to the desired location as the file there was locked by the worker process. I tried various solution to do with creating my own appdomain. I didn't get much success with these. You will have to do this if you want to unload your assemblies at any point though, as AppDomain.Unload unloads the whole domain.

Anyway... it turned out that the best solution for me was to get to shadow copy the assembly for me. This was as simple as putting the following code in your ApplicationStart in Global.aspx.cs

+ ";" + Server.MapPath("~\plugins"));

For further information look here, here and here.

No comments:

GitHub Projects