1

I'm using MEF in a plugin based ASP.NET application. Wiring up a File System Watcher with Container.Refresh() any new plugin is loaded automatically upon being copied to the plugin folder.

The problem is when I want to delete or replace a loaded plugin. It is locked by w3wp and cannot be deleted. I read about Shadow Copy but cannot find a good example or article.

Xaqron
  • 29,931
  • 42
  • 140
  • 205

2 Answers2

1

Try adding the plugin folder to AppDomainSetup.ShadowCopyDirectories. This property is a semicolon-seperated list of directories containing assemblies that should be loaded via shadow copies.

Normally you also need to set AppDomainSetup.ShadowCopyFiles to "true" but I think this is already the default for ASP.NET appdomains.

However, be aware that loading a new version of a plugin will not magically unload the old version. The only way to do that is to unload the AppDomain containing it. Since this requires you to load plugins in a separate appdomain, this is probably more trouble than it is worth.

It is probably simpler, safer and more effective to just stop the service, update the DLLs, and restart.

Wim Coenen
  • 66,094
  • 13
  • 157
  • 251
0

Make sure you are cleaning up all your unmanaged resources properly. It sounds like you may have opened a file stream but didn't properly close/dispose of it, and this may lock up a file by the process that was working with it in the first place. More info on using statement here: http://www.blackwasp.co.uk/UsingStatement.aspx

Kon
  • 27,113
  • 11
  • 60
  • 86