Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

add the reference of  dll dynamically  and use the dll in VB.NET

Posted on 2004-09-20
8
Medium Priority
?
785 Views
Last Modified: 2011-04-14
Hello..
I am making one application in VB.NET in which I want to  dynamically add tne reference of
one dll in my application.
I have the dll which calls method "createhtm" along with these parameters ..

(path, nFileName, Outputpath)

How will I add the reference and use the dll dynamically.


Pls do let me  know
0
Comment
Question by:rajender123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 3

Expert Comment

by:imu79
ID: 12102339
As far as I know, you cannot add a reference dynamically.
However, there are some ways you can call a method dynamically. It depends on what type of dll you have. Is it a .NET dll or a COM dll?

0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12103223
Why would you want to add in dynamically?
0
 
LVL 41

Expert Comment

by:graye
ID: 12107515
Sure you can dynamically bind to a DLL at runtime...   It's not recommended since it violates the entire .Net security structure.   That also means, you won't find any examples on how to do it on the Microsoft web site.

Here is a chunk of a working program that demonstrates how to dynamically load a DLL "plug-in" module at runtime.

        Dim Assmbly As Reflection.Assembly
        Dim PlugInType As Type
        Dim ProbePlugIn As PlugInBase.PlugInBase
        Dim PlugInName, temp As String

        ' load the plug-in DLL
        temp = Split(cbFeature.SelectedItem.ToString, "(")(1)
        PlugInName = Split(temp, ")")(0)
        Try
            ' If running under the IDE, then always get the development version of the
            ' plugin DLL from it's development directory (which is a subdirectory under
            ' this developement directory).
            If System.Diagnostics.Debugger.IsAttached Then
                Assmbly = Reflection.Assembly.LoadFrom(Application.StartupPath & "\..\" & PlugInName & "\bin\" & PlugInName & ".dll")
            Else
                Assmbly = Reflection.Assembly.LoadFrom(Application.StartupPath & "\" & PlugInName & ".dll")
            End If
            PlugInType = Assmbly.GetType(Assmbly.GetName.Name & "." & PlugInName, True, True)
            ProbePlugIn = CType(Activator.CreateInstance(PlugInType), PlugInBase.PlugInBase)
        Catch ex As Exception
            MsgBox("Yikes!, can't find the " & PlugInName & ".dll plug-in" & vbCr & ex.message, MsgBoxStyle.Exclamation, "Internal Program Error")
            Exit Sub
        End Try
0
 

Author Comment

by:rajender123
ID: 12109174
Hi graaye..
well i tried your code..but it was not working..

after this line it went to exception line(catch error)
   PlugInType = Assmbly.GetType(Assmbly.GetName.Name & "." & PlugInName, True, True)

can u let me knwo how to use the methods  of the dll...............
well second thing how to add the refrence for PlugInBase.PlugInBase
Psl help me out..
its realyy urgent
0
 
LVL 41

Accepted Solution

by:
graye earned 200 total points
ID: 12111165
The chunk of code was only meant to serve as an example... not a complete solution.  Let me explain a bit more about this particular example...  perhaps that will help

This program accepts any number of "plug in" DLL modules to add functionality to the "main" program.  The main program gets its list of available DLL files from the App.config file... and I place the list into a ComboBox.  The user selects one of the DLL plugins, and I load that DLL file.

In order to load a .Net Class DLL file into another program, the recieving program must know something about the "foriegn" DLL.  (Unlike an Active-X DLL of just a few years ago, there aren't any  built-in mechanisms for autodiscovery... the ability to discover the list of methods and properties on the fly).  For a .Net Class DLL... you have have a .Net Reference in the calling program.

Ah... I can see your mind working....  Yes, that does cause a problem...  after the "main" program is compiled and distributed, how on Earth could I later go back and add a Reference to a newly developed DLL?

The answer is... you don't.   Instead of adding a reference to the Class DLL itself, you instead add a reference to a "generic" base Class (from which the real plugin classes are derived).   Now the main program is expecting a base class module... but instead it loads any number of derived class modules.  It doesn't know any different... it thinks it's loading a base class.

So, to answer your questions... if the design of your project is similar to mine (I have no idea)... then you'd develope a base class DLL in a separate VB.Net project.  You'd then add a "Project Reference" to this base class to your main program.   Then you'd create a 2nd "real" class project that derives from the base class.

So, am I at least close?   I thought my example was a bit odd-ball.  What exactly are you trying to do?
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

715 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