|
-
Apr 29th, 2002, 04:33 AM
#1
Thread Starter
Junior Member
Oops!! How to unload the Assembly *Hell* !!! Nothing works !!
Dear all,
I opened an Assembly using Assembly.LoadFrom() method, did some work and set null. After that when i tried to delete that assembly file, its locked and couldn't remove it.
I tried using AppDomain also, to load that assembly in seperate appdomain and unloaded it using AppDomain.UnLoad also. It doesn't work. Nothing works. I can delete only when my app exits. I absolutely need of this assembly unload in my app.
Experts !!!, how to unload the Assembly *hell*.
Any help would be greatly appreciated.
Regards
Rafik.
-
Apr 29th, 2002, 07:44 AM
#2
Lively Member
You can't unload a specific assembly, only an AppDomain.
You should use the static Unload method of the AppDomain class.
AppDomain.Unload(YourAppDomain)
Note 1
You can't unload the default AppDomain.
Note 2
If you use LoaderOptimization MultiDomain your assemblies get loaded in a domain neutral fashion, then the assembly gets locked until the whole process exits.
-
Apr 29th, 2002, 08:11 AM
#3
Lively Member
Another note, setting a variable to null/nothing worked in the old world but in .NET anymore.
When a Garbage Collection takes place the GC will detect that the specific variable isn't used anymore and will be Garbage Collected, so setting something to null/nothing has no effect anymore.
-
Apr 30th, 2002, 12:37 AM
#4
Thread Starter
Junior Member
Hi,
Ya, i tried unloading my own appdomain only not assembly.
I created seperate appdomain, loaded my assembly in it, done work, unloaded that appdomain using AppDomain.Unload(myAppDomain) method.
I doesn't work. Thanx for u'r info about setting to null.
But, AppDomainSetup 's ShadowCompyFiles property set to "true" will solve our problem, but yet to check.
Rafik
-
Apr 30th, 2002, 04:39 AM
#5
Lively Member
Take a look at the below code how to do it:
public static void Main(string[] args)
{
AppDomain appDomain = AppDomain.CreateDomain("NewAppDomain");
appDomain.DoCallBack(new CrossAppDomainDelegate(LoadAssembly));
Console.WriteLine("Try to delete Assembly now"); // Delete/Overwrite will fail now
Console.ReadLine();
AppDomain.Unload(appDomain);
Console.WriteLine("AppDomain unloaded");
Console.WriteLine("Try to delete Assembly now"); // Delete/Overwrite wouldn't fail now
Console.ReadLine();
}
public static void LoadAssembly()
{
Assembly assembly = Assembly.LoadFrom(@"c:\MyClassLibrary.dll");
Console.WriteLine("Assembly loaded in {0}",AppDomain.CurrentDomain.FriendlyName);
}
BTW:
ShadowCoping makes a copy of the original Assemblies specified in AppDomain.ShadowCopyDirectories and loads the copy, so the copy gets locked not the original ones.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|