Results 1 to 6 of 6
  1. #1
    ♪~ ᕕ(ᐛ)ᕗ's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    Uterus
    Posts
    9,119
    Reputation
    1096
    Thanks
    1,970
    My Mood
    Doh

    Adding a reference programmatically [solved]

    So yea, I'm working on a project right now and I need a way to add a reference programmatically on my project. Can somebody tell me how?

  2. #2
    freedompeace's Avatar
    Join Date
    Jul 2010
    Gender
    female
    Posts
    3,033
    Reputation
    340
    Thanks
    2,792
    My Mood
    Sad
    You can lazy load using System.Reflection.Assembly.Load()

  3. #3
    ♪~ ᕕ(ᐛ)ᕗ's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    Uterus
    Posts
    9,119
    Reputation
    1096
    Thanks
    1,970
    My Mood
    Doh
    So yea something like this?
    Code:
    Dim ass As Assembly = Assembly.LoadFile("D:\ex.dll")
            Dim mods As [Module] = ass.GetModule("Module1")
            Dim load As MethodInfo = mods.GetMethod("Load")
            load.Invoke(Nothing, Nothing)
    EDIT:
    New Code:
    [highlight=vb.net] Public Sub LoadPlugin(ByVal name As String)
    Dim ass As Assembly = Assembly.LoadFrom(name)
    Dim t As Type = ass.GetType("Test.Plugin.Load")
    Dim m As MethodInfo = t.GetMethod("L")
    Dim o As Object = Activator.CreateInstance(t)
    m.Invoke(o, Nothing)
    End Sub[/highlight]
    But at Dim m As MethodInfo....etc...It shows me an error, "Reference is not set to an instance of an object."
    Last edited by ♪~ ᕕ(ᐛ)ᕗ; 06-11-2011 at 08:40 AM.

  4. #4
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Quote Originally Posted by Horatio Caine View Post
    So yea something like this?
    Code:
    Dim ass As Assembly = Assembly.LoadFile("D:\ex.dll")
            Dim mods As [Module] = ass.GetModule("Module1")
            Dim load As MethodInfo = mods.GetMethod("Load")
            load.Invoke(Nothing, Nothing)
    EDIT:
    New Code:
    [highlight=vb.net] Public Sub LoadPlugin(ByVal name As String)
    Dim ass As Assembly = Assembly.LoadFrom(name)
    Dim t As Type = ass.GetType("Test.Plugin.Load")
    Dim m As MethodInfo = t.GetMethod("L")
    Dim o As Object = Activator.CreateInstance(t)
    m.Invoke(o, Nothing)
    End Sub[/highlight]
    But at Dim m As MethodInfo....etc...It shows me an error, "Reference is not set to an instance of an object."
    Dim t As Type = ass.GetType("Test.Plugin.Load")

    Verify that that name actually exists, chances are there is no type with that name.

    [highlight=vb.net]
    If (ass.GetTypes().Select(Function(T As Type) T.Name).Contains("Test.Plugin.Load")) Then
    MessageBox.Show("Type name exists!")
    Else
    MessageBox.Show("No type with that name exists")
    End If
    [/highlight]

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  5. #5
    ♪~ ᕕ(ᐛ)ᕗ's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    Uterus
    Posts
    9,119
    Reputation
    1096
    Thanks
    1,970
    My Mood
    Doh
    Well it says that no type with that name exists.
    Here's the remote DLL's code:
    [highlight=vb.net]Namespace Test.Plugin

    Public Class Load

    Public Shared Sub L()
    MsgBox("Ace")
    End Sub

    End Class


    End Namespace[/highlight]

    [highlight=vb.net] Public Sub LoadPlugin(ByVal name As String)
    Dim ass As Assembly = Assembly.LoadFrom(name)
    For Each x In ass.GetTypes
    If x.Name = "Load" Then
    Dim m As MethodInfo = x.GetMethod("L")
    Dim o As Object = Activator.CreateInstance(x)
    m.Invoke(o, Nothing)
    End If
    Next
    End Sub[/highlight]
    I've got it working ^^
    Thanks a lot guys
    @Jason /req closed
    Last edited by ♪~ ᕕ(ᐛ)ᕗ; 06-12-2011 at 04:23 AM.

  6. #6
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Marked solved then.

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  7. The Following User Says Thank You to Jason For This Useful Post:

    ♪~ ᕕ(ᐛ)ᕗ (06-12-2011)