Link to home
Start Free TrialLog in
Avatar of rajender123
rajender123

asked on

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

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
Avatar of imu79
imu79

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?

Why would you want to add in dynamically?
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
Avatar of rajender123

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of graye
graye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial