Default AppDomain and Assembly Reload



I am a little stuck. An application that I am maintaining loads
plug-ins but only uses the default app domain and thus cannot unload
them. That's how it is. It also has its plug-in assemblies frequently
updated and forces the user to restart the application each time.

I have managed to get a default app domain to let me overwrite a
plug-in's assembly via shadow copying, but for the life of me I cannot
get the final part done -- that being loading up the new assembly. The
old assembly is once again reloaded.

Now I understand that I cannot unload an assembly from within an app
domain without unloading the entire app domain. This is not an option
with the default app domain short of restarting the application. But
can I not simply load up a second differently versioned assembly into
the same app domain? (They are not GAC'ed) Btw... I had to use
deprecated calls to get this far since the
AppDomain.CurrentDomain.SetupInformation property can in effect no
longer be modified since the initialization is done. (It appears a
change of heart took place in design at some point in time.)

If not, what are my options?

[STAThread]
static void Main()
{
AppDomain.CurrentDomain.SetShadowCopyFiles();

AppDomain.CurrentDomain.SetShadowCopyPath(AppDomain.CurrentDomain.BaseDirectory);

Assembly workerAssembly = Assembly.Load(@"p1,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");

object lateBoundObj =
workerAssembly.CreateInstance("Plugins.MyClass", true,
BindingFlags.Default, null, null /*args*/, null, null);

....

// time out... overwrite the assembly file now since we are
using the shadow copy

// re-load the new image
workerAssembly = null;
workerAssembly = Assembly.Load(@"p1, Version=1.0.0.1,
Culture=neutral, PublicKeyToken=null");

lateBoundObj =
workerAssembly.CreateInstance("Plugins.MyClass", true,
BindingFlags.Default, null, null /*args*/, null, null);


So I am able to overwrite my DLL at the "timeout" point. But the Load
call for the 1.0.0.1 version loads the 1.0.0.0 version again.

Thx in advance.

.



Relevant Pages

  • Re: CodeDom V Emit with Dynamic Proxy
    ... Thanks as well for informing me about the assemblies not being unloaded. ... I'll have to make a note to unload the service after so many minutes of idle time. ... service client and marshaled the calls between my main app domain and the ... A product we need to integrate with exposes a web service BUT its methods ...
    (microsoft.public.dotnet.framework.clr)
  • Re: Warm up Scripts
    ... Assemblies are assigned to named domains using assignment ... In this section the user may specify defualt configuration for any app ... Specify -1 to signal that an app domain should never ... domain should never unload when idle but not empty. ...
    (microsoft.public.biztalk.general)
  • Re: CodeDom V Emit with Dynamic Proxy
    ... .NET assemblies are never unloaded unless you unload ... service client and marshaled the calls between my main app domain and the ... A product we need to integrate with exposes a web service BUT its methods ...
    (microsoft.public.dotnet.framework.clr)
  • Re: CodeDom V Emit with Dynamic Proxy
    ... .NET assemblies are never unloaded unless you unload ... service client and marshaled the calls between my main app domain and the ... A product we need to integrate with exposes a web service BUT its methods ...
    (microsoft.public.dotnet.framework.clr)
  • Re: Dynamic creation of object problem
    ... ASP.NET makes a shadow copy of the assemblies it loads, ... assemblies in the bin directory are never locked by the worker ... There is no way to unload an assembly from an app domain. ... >loads assemblies, looking for objects that implement a particular interface. ...
    (microsoft.public.dotnet.framework.aspnet)

Loading