Solved

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

Posted on 2007-12-04
5
1,935 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
ID: 20405827
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
ID: 20405953
Thanks - could you elaborate a little more? Maybe an example?
0
 
LVL 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 150 total points
ID: 20406048
0
 
LVL 38

Accepted Solution

by:
PaulHews earned 350 total points
ID: 20406386
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
ID: 20460122
that seems to help out alot more!

thanks!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

809 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