Dynamic Load Assembly
From: BrianS (BrianS_at_discussions.microsoft.com)
Date: 01/06/05
- Next message: Kit George: "RE: Getting a problem while developing outlookaddin with c#.net form"
- Previous message: Marc Bernard: "Re: Scripting Engine (somewhat advanced)"
- Next in thread: BrianS: "RE: Dynamic Load Assembly"
- Reply: BrianS: "RE: Dynamic Load Assembly"
- Reply: David Levine: "Re: Dynamic Load Assembly"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 6 Jan 2005 09:49:02 -0800
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: Kit George: "RE: Getting a problem while developing outlookaddin with c#.net form"
- Previous message: Marc Bernard: "Re: Scripting Engine (somewhat advanced)"
- Next in thread: BrianS: "RE: Dynamic Load Assembly"
- Reply: BrianS: "RE: Dynamic Load Assembly"
- Reply: David Levine: "Re: Dynamic Load Assembly"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|