I am using the following to Dynamically load a dll in vb.net I am using the LoadPlugins method to use an AggregateCatalog To find the plugins in the directory called Extensions all that is working perfect and i run the dll with the second listing below as you can see im using lazy loading of the classes below
Imports System.ComponentModel.Composition Imports System.ComponentModel.Composition.Hosting
My Problem is how do i exit the dll application properly is it just simple enough to use Applicaiton.Exit in the dll or will this still reside in memory until the main application ends?.
First Code Listing
Private Sub LoadPlugins()
' Add any initialization after the InitializeComponent() call.
'An aggregate catalog that combines multiple catalogs
Dim catalog = New AggregateCatalog()
'Adds all the parts found in the same assembly as the Program class
catalog.Catalogs.Add(New AssemblyCatalog(GetType(frmMainImports).Assembly()))
'IMPORTANT!
'You will need to adjust this line to match your local path!
catalog.Catalogs.Add(New DirectoryCatalog("Extensions"))
'Create the CompositionContainer with the parts in the catalog
_container = New CompositionContainer(catalog)
'Fill the imports of this object
Try
_container.ComposeParts(Me)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Second Code Listing
Private Sub btnRunImport_Click(sender As Object, e As EventArgs) Handles btnRunImport.Click
Try
For Each i As Lazy(Of IImport, IMetaName) In extensions
'Search for matching extension name then invoke MyMethod in that extension then
'set textbox1.text to the return value
If i.Metadata.MyName = lbPlugins.SelectedItem Then txtDescription.Text = i.Value.Import("Hello From")
Next
Catch ex As Exception
MsgBox(ex.ToString)
End Try