VSIP: Assembly file handles not being released after AppDomain.Unload - by Jamie Cansdale

Status : 

  By Design<br /><br />
		The product team believes this item works according to its intended design.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 536783 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 2/26/2010 5:19:32 AM
Access Restriction Public


This happens when executing inside the Visual Studio 2010 process, but not when executing inside the default MSTest process (use the VS SDK's "VS IDE" HostType for repro).

When an assembly is loaded in a new app domain inside Visual Studio 2010, the assembly file handle remains locked after the app domain is unloaded. This appears to happen when the assembly is loaded into the 'Load' context, but not when loaded into the 'LoadFrom' context.

This issue could impact any add-in or package that needs to execute or examine assemblies in an isolated app domain. The most likely symptom is the target project will fail to build until Visual Studio is restarted.
Sign in to post a comment.
Posted by Jamie Cansdale on 2/27/2010 at 9:58 AM
Thanks, this works great!
Posted by Microsoft on 2/26/2010 at 12:55 PM
There was a change made to the default CLR loader optimization behavior used for Visual Studio 2010 (for performance reasons). In 2008 and prior, we used MultiDomainHost loading. In 2010, this was changed to MultiDomain. (You can find more details on this doc topic: http://msdn.microsoft.com/en-us/library/43wc4hhs.aspx).

To get the MultiDomainHost behavior (which will release a file handle on an Assembly when the AppDomain is unloaded), you should set the LoaderOptimization property on the AppDomainSetup object for your AppDomain as follows:

appDomainSetup.LoaderOptimization = LoaderOptimization.MultiDomainHost;

Thank you for taking the time to file a bug report!

Visual Studio Platform Team