HighTechTalks DotNet Forums  

Default AppDomain and Assembly Reload

Dotnet Framework (CLR) microsoft.public.dotnet.framework.clr


Discuss Default AppDomain and Assembly Reload in the Dotnet Framework (CLR) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
MD
 
Posts: n/a

Default Default AppDomain and Assembly Reload - 09-22-2006 , 04:04 AM






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(AppDomai n.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.


Reply With Quote
  #2  
Old   
David Levine
 
Posts: n/a

Default Re: Default AppDomain and Assembly Reload - 09-23-2006 , 06:21 AM






You can load up multiple versions of the same assembly, but I believe the
fusion layer considers the path to be part of the assembly's identity, so if
all you are doing it overwriting an assembly it will probably keep using the
one already loaded into memory. As an experiment try copying the new
assembly to a different subdirectory (e.g. <simpleName>.<version>) and see
if you can get the new assembly version to load, or you can try renaming it
slightly.

IMO you should be using multiple appdomains so that you can unload the old
versions. Since you are maintaining the code presumably you can modify it.
Or just restart it.

"MD" <martin.douglas (AT) gmail (DOT) com> wrote

Quote:
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(AppDomai n.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.




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.