user1247808
user1247808

Reputation: 401

call a shared method in a loaded dll using class name

sample.vb
class sam
public shared sub hh()
Console.WriteLine("asasas")
end sub
end class

test.vb
Dim ass as Assembly  = Assembly.LoadFile("sample.dll")

Now, I want to call the shared method using the class name.How do i do that??

Upvotes: 0

Views: 2718

Answers (1)

John Alexiou
John Alexiou

Reputation: 29244

Reflection is your friend. Add a Imports System.Reflection and try the following:

Sub Main()
    Dim ass As Assembly = Assembly.LoadFile("sample.dll")
    Dim t_sam As Type = ass.GetType("sam")
    Dim hh_m As MethodInfo = t_sam.GetMethod("hh", BindingFlags.Public Or BindingFlags.Static)
    hh_m.Invoke(Nothing, New Object() {})
End Sub

Upvotes: 2

Related Questions