C# DLL unloading appdomain



Hello,

I've finally managed to remotely load a DLL. I've expanded the code to
load it in a seperate domain to unload the appdomain, which works to a
certain extend.
The host application always keeps the entry DLL in memory. How can I
also unload this main DLL? As it's left after unloading the appdomain.
The dll is loaded in the hostapplication at "Assembly assembly =
appdom.Load(RawAssembly)".

How can I avoid this behaviour? I would like to invoke a method and
unload the everything dynamically loaded.

Thanks in advance!

The code fragment:

byte[] RawAssembly = getFileArray(FileName);
// AppDomain.CurrentDomain loads also an instance
Assembly assembly = appdom.Load(RawAssembly);

//Assembly assembly = Assembly.LoadFile(FileName);
foreach (AssemblyName ASSN in
assembly.GetReferencedAssemblies())
{
try
{
appdom.CreateInstance(ASSN.Name,
ASSN.GetType().Name);
//
Activator.CreateInstance(ASSN.GetType());
}
catch (Exception e)
{
// MessageBox.Show(e.Message);
}
}
foreach (Type type in assembly.GetTypes())
{
if (!type.IsClass || type.IsNotPublic)
continue;
Type[] interfaces = type.GetInterfaces();
//object obj = Activator.CreateInstance(type);
System.Runtime.Remoting.ObjectHandle t =
appdom.CreateInstance(assembly.GetName().ToString(), type.FullName);
tList.Add(t);
}

.



Relevant Pages

  • Re: loading dll at runtime
    ... //when i create the dll in another folder can't load it i get the Assembly ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Delete dll
    ... >I want to unload the dll after use so I can delete the stored .dll file from ... >How do I unload the dll, or release the file so it may be deleted? ... You can explicitly load the library before calling anything in it ...
    (microsoft.public.vb.com)
  • Re: Delete dll
    ... >I want to unload the dll after use so I can delete the stored .dll file from ... >How do I unload the dll, or release the file so it may be deleted? ... You can explicitly load the library before calling anything in it ...
    (microsoft.public.win32.programmer.ole)
  • Re: loading dll at runtime
    ... but what i understand ..once a dll is loaded in the current domain it can ... I guess i need to find a way to get Assembly info b4 i load it into the ... Currently i use xsl to do the customer specific..but the files can be pretty ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How do i dynamicaly load and unload a C# dll at runtime
    ... how do i access methods when the .net assembly was loaded with late biding? ... To unload though you'll need to learn ... When you load a dll, ...
    (microsoft.public.dotnet.framework)

Loading