RE: Dynamic Load Assembly

From: BrianS (BrianS_at_discussions.microsoft.com)
Date: 01/06/05

  • Next message: Joakim Karlsson: "Re: Unexpected integer addition result"
    Date: Thu, 6 Jan 2005 12:43:04 -0800
    
    

    In otherwords,

    AppDomain.CurrentDomain.GetAssemblies

    returns an unloaded/unreferenced assembly.why?

    "BrianS" wrote:

    > I have Web Service (A) that dynamically loads a private assembly (B). I do
    > NOT reference B in A. ( I do reference A in B, but that should not matter?).
    > Both these Assemblies reside in the A's /Bin.
    >
    > I dynamically load B and Invoke a Method:
    >
    > 'Create evidence for the new appdomain.
    > Dim adevidence As System.Security.Policy.Evidence =
    > AppDomain.CurrentDomain.Evidence
    >
    > ' Create the new application domain.
    > Dim domain As AppDomain = AppDomain.CreateDomain("MyDomain",
    > adevidence,AppDomain.CurrentDomain.SetupInformation)
    > Dim myAssembly As [Assembly] = domain.Load(strAssemblyName)
    > Dim sysType As Type = myAssembly.GetType(strClassName)
    >
    > obj = Activator.CreateInstance(sysType, New Object())
    >
    > ' Invoke the method
    > Dim intBindings As Integer = BindingFlags.DeclaredOnly Or
    > BindingFlags.Public Or BindingFlags.NonPublic Or BindingFlags.Instance Or
    > BindingFlags.InvokeMethod
    > returnObj= obj.GetType.InvokeMember(strMethod, intBindings, Nothing, obj,
    > New Object())
    >
    > ' Unload the application domain.
    > AppDomain.Unload(domain)
    >
    > It was my understanding to load the assembly into a new AppDomain so I can
    > explicity Unload the AppDomain to free resources.
    >
    > However, when I excecute my Web Service (A) and I am on the Service Page
    > (where all methods are listed) I see that B has already been loaded in the
    > aspnet_wp.exe process using Process Explorer?
    >
    > Why would this be? Is it because, using the Load context, since assemblies
    > reside in the same path, .Net automactically loads them at startup?
    >
    > I tried commenting out the code above, but it still loads the assembly at
    > startup.
    >
    >


  • Next message: Joakim Karlsson: "Re: Unexpected integer addition result"

    Relevant Pages

    • Re: ASP.NET 2.0 (beta) and Reflection
      ... I'm not sure if there's an easier way to get a reference to the assembly, ... but once you do you'll want to load the Constructor info and hang on to it ... By caching the ConstructorInfo you can load the assembly quickly. ... since there could be tons of system assemblies loaded. ...
      (microsoft.public.dotnet.framework.aspnet)
    • Loading Assemblies from several directories.
      ... an application needs to load several users ... load it's own code (which reference ... to a 3rd party dll) and then execute its code, ... I /can/ get all those assemblies to run if I use Assembly.LoadFrom, ...
      (microsoft.public.dotnet.framework)
    • Re: Stepping into a referenced assembly
      ... Steve ... > Both g_toc and g_RegCtl are instance variables created from the assemblies ... > that I have reference and when I step through the code above, ... but it won't load the class for g_toc from that assembly so I ...
      (microsoft.public.dotnet.languages.vb)
    • Re: Dynamically loading assemblies...
      ... creating a dedicated AppDomain and then shutting it down to ... unload the assembly loaded seems to be the only option for now. ... For example in c++ I would load a dll ... this creates a lot of overhead to simply be able to unload those assemblies ...
      (microsoft.public.dotnet.languages.csharp)
    • Re: load unload assembly
      ... you cant unload an assembly from an AppDomain. ... AppDomain, load your temporary assembly into the new AppDomain, use it to ... > You can't unload individual assemblies. ...
      (microsoft.public.dotnet.framework.clr)