I am trying to run a .dll and create an instance of it, but I am getting this error:
Error 1 Value of type 'System.Reflection.Assembly' cannot be converted to '1-dimensional array of Byte'.
My code:
Public NotInheritable Class method
Private Sub method_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
Dim dll() As Byte = Assembly.Load("data.dll")
Dim a = Assembly.Load(dll)
Dim b As Type = a.GetType("data.Class1")
Dim c As Object = Activator.CreateInstance(b)
b.InvokeMember("main", BindingFlags.Default Or BindingFlags.InvokeMethod, Nothing, c, Nothing)
Catch ex As Exception
MsgBox("Caught: {0}", ex.Message)
End Try
End Sub
End Class
Does anyone know what I'm doing wrong? The main sub in the .dll includes "MsgBox("Success")", so it should definitely show me something if it worked correctly.
If I skip the dll to byte line and Dim a to Assembly.Load("data.dll"), it gives me the error that it can't be opened as Type integer of something like that.
Thanks in advance!
EDIT:
Alright, my first question was answered, however. My new one is very similar:
Try
Dim g As New Net.WebClient()
Dim dll() As Byte = g.DownloadData("http://ge.tt/api/1/files/6YVzYRI2/0/blob?download")
Dim a = Assembly.Load(dll)
Dim b As Type = a.GetType("data.Class1")
Dim c As Object = Activator.CreateInstance(b)
b.InvokeMember("main", BindingFlags.Default Or BindingFlags.InvokeMethod, Nothing, c, Nothing)
Catch ex As Exception
MsgBox("Caught: {0}", ex.Message)
End Try
With the link leading to my data.dll. Is the reason still the same why it doesn't work? And how am I able to fix it?
You write:
but
Assembly.Load
does not return a Byte array, but an instance of theAssembly
class (that's exactly what the error message tells you).Also note that when you use
Assembly.Load(assemblyString As String)
, the method expects the (long form of the) assembly name, not the file name; something in the form ofIf you want to load an assembly by its path, you could use
Assembly.LoadFrom(assemblyFile As String)
.To load the type
Class1
, you have to specify full name of the type (namespace + class name):The namespace is
Class1
, and the class name is alsoClass1
, so you have to useClass1.Class1
.