On 12 jul, 18:22, Peter Bromberg [C# MVP]
<pbromb...@yahoo.yabbadabbadoo.com> wrote:
> Tim,
> You can't. You can create a new AppDomain, load an assembly into it, and
> call methods in the remotely loaded assembly, and tear down the secondary
> Appdomain, but the only way you can unload an assembly from your primary
> appDomain is the tear down the primary appDomain itself.
> Peter
> --
> Site: http://www.eggheadcafe.com
> UnBlog: http://petesbloggerama.blogspot.com
> BlogMetaFinder(BETA): http://www.blogmetafinder.com
>
> "Tim" wrote:
> > 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);
> > }
Peter, Thanks for you quick reply!
Is there a way to invoke methods on the dynamic assembly without
loading it in the main appdomain?