Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / September 2006

Tip: Looking for answers? Try searching our database.

Default AppDomain and Assembly Reload

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
MD - 22 Sep 2006 09:04 GMT
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.
David Levine - 23 Sep 2006 11:21 GMT
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.

>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
[quoted text clipped - 50 lines]
>
> Thx in advance.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.