views:

139

answers:

1

Is there a way to unload the default .NET AppDomain from an unmanaged application?

I'm using a third party tool called .NET Extender for using .NET assemblies from within Visual FoxPro which allows me to host .NET controls and also make use of .NET classes and methods from within a FoxPro environment.

The problem I'm having is that when debugging an application from within Visual FoxPro it runs the everything under the main vfp9.exe application file for the IDE and it appears that handles to my managed assemblies are not released. So when I make a change to these .NET assemblies and want to update them I have to close the VFP IDE and reopen it otherwise I get a sharing violation when attempting to overwrite the files.

I started looking into ways of ensuring that the controls are disposed but then I came across this article by Rick Strahl where he basically describes that the problem is really that the main AppDomain isn't unloaded. After looking through information about how to unload the default AppDomain I've come to the conclusion that this isn't possible at least from a managed application but is it possible for an unmanaged application. My thought is that just because an unmanaged application has used a .NET resource it shouldn't have to continue to carry around the AppDomain and Runtime baggage.

A: 

This question was answered on the MSDN Forums and unfortunately it appears that this is not possible and that a process must be terminated to release resources including app domains. This is described in the documentation for the ICLRRuntimeHost.Stop interface method where it states "This method does not release resources to the host, unload application domains, or destroy threads. You must terminate the process to release these resources."

jpierson