1: Public Sub ExecuteOnAppDomain(ByVal typeName As String, ByVal assemblyName As String)
2: Dim domainSetup As AppDomainSetup = New AppDomainSetup
3: domainSetup.ApplicationBase = Environment.CurrentDirectory
4: domainSetup.PrivateBinPath = "RELATIVE_FOLDER"
5: ' Copia delle policy dall'appdomain corrente
6: Dim adevidence As Evidence = AppDomain.CurrentDomain.Evidence
7: ' Creazione nuovo appdomain
8: Dim domain As AppDomain = AppDomain.CreateDomain("SomeAppDomain", adevidence, domainSetup)
9:
10: ' Argomenti costruttore
11: Dim constructorArgs As New List(Of Object)
12: constructorArgs.Add("PARAM1")
13: ' ....
14: ' ....
15: constructorArgs.Add(10)
16: ' Bindings
17: Dim bindings = BindingFlags.CreateInstance Or BindingFlags.Instance Or BindingFlags.Public
18: ' Creazione della classe dato il nome completo e l'assembly di riferimento
19: Dim obj = domain.CreateInstanceAndUnwrap(assemblyName, typeName, False, bindings, Nothing,
20: constructorArgs.ToArray, Nothing, Nothing, Nothing)
21: obj.DoWork()
22: ' Unload dell'appdomain
23: AppDomain.Unload(domain)
24: End Sub