Solved

Loading modules (.dll) dynamically in VB.Net 2005

Posted on 2007-12-04
5
1,932 Views
Last Modified: 2008-02-01
Hi all,

i'm wondering if it is possible (and how) to dynamically load pieces of my program.

I'd like to create different parts of my program and compile them as dll's.  Then my main program will load the dll's that it finds in a folder.

For example,

in my .\Plugins folder I have the following:

Orders.dll
Inventory.dll
Customers.dll

(each of them is part of a GUI - with interfaces to access a Panel, MenuItem, and TreeNode)

when my program loads, it will look in .\Plugins and load each of the dlls it finds (each one will have the same entry format)

on an update i add Ledger.dll to the .\Plugins folder, and the next time the program runs, it loads Ledger.dll also.

can this be done? or do i need to hard-code the declarations?

thanks!

J
0
Comment
Question by:sgaggerj
  • 2
  • 2
5 Comments
 
LVL 38

Assisted Solution

by:PaulHews
PaulHews earned 350 total points
Comment Utility
It can be done.  Assuming you want them to derive from a common interface, you create the interface first in an assembly, and reference that in both the client and plugins.  Then you can create instances using reflection.
Private Function GetPluginFromAssembly(ByVal PluginAssembly As String, ByVal PluginClassName As String, ByVal PluginAssemblyPath As String) As PluginBase.IPlugin

    Dim oCurrentAssembly As [Assembly] = System.Reflection.Assembly.GetExecutingAssembly()

    Dim oTemplateAssembly As [Assembly]

    Dim oPlugin As Object

    Dim sTemplateNameAndPath As String = System.IO.Path.Combine(PluginAssemblyPath, PluginAssembly)

    If System.IO.File.Exists(sTemplateNameAndPath) Then

        oTemplateAssembly = Assembly.LoadFrom(sTemplateNameAndPath)

        oPlugin = Activator.CreateInstance(oTemplateAssembly.GetType(PluginClassName, True))

        Return CType(oPlugin, PluginBase.IPlugin)

    End If
 

End Function

Open in new window

0
 
LVL 1

Author Comment

by:sgaggerj
Comment Utility
Thanks - could you elaborate a little more? Maybe an example?
0
 
LVL 69

Assisted Solution

by:Éric Moreau
Éric Moreau earned 150 total points
Comment Utility
0
 
LVL 38

Accepted Solution

by:
PaulHews earned 350 total points
Comment Utility
It's fairly involved.  There are some articles that can walk you through all the concepts:

Interfaces
http://www.developer.com/lang/other/article.php/939411

Plugin architecture in vb.net
http://www.developerfusion.co.uk/show/4371/
0
 
LVL 1

Author Comment

by:sgaggerj
Comment Utility
that seems to help out alot more!

thanks!
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now