Peter Goodman bio photo

Peter Goodman

A developer living in Auckland building software using all sorts of bits and pieces I find along the way. Originally from Northern Ireland.

Twitter Google+ LinkedIn Github

Recently I was using a new AppDomain from within a Visual Studio package to reflect over a dll and get some metadata. I then unloaded the AppDomain expecting that the file locks on the dll file would be released…..but they weren’t.

I could see that another AppDomain in VS was holding a lock on my file. You can see this by switching on Native debugging when attaching another visual studio instance and from the immediate window use:

.load sos


It turns out this is due to the LoaderOptimization attribute. Set this property to SingleDomain on your AppDomainSetup object to allow the file lock to be freed when unloading your AppDomain. This translates as.

Indicates that the application will probably have a single domain, and loader must not share internal resources across application domains.