当我尝试调用程序集(vb.net windows窗体应用程序)时,我收到错误“System.Reflection.TargetInvocationException”或“System.Reflection.TargetParameterCountException”。 “confusethis.exe”来源:
Public Class mainform
Private Sub mainform_Load(sender As Object, e As EventArgs) Handles MyBase.Load
MsgBox("test")
End Sub
End Class
这是我调用的来源:
Dim instance As FileStream = File.Open("confusethis.exe", FileMode.Open)
Dim br As New BinaryReader(instance)
Dim bin As Byte() = br.ReadBytes(Convert.ToInt32(instance.Length))
instance.Close()
br.Close()
Dim a As Assembly = Assembly.Load(bin)
Dim method As MethodInfo = a.EntryPoint
If (IsDBNull(method) = False) Then
Dim o As Object = a.CreateInstance(method.Name)
method.Invoke(o, New Object() {New String() {"param1"}})
Else
MsgBox("error!")
End If
我试过改变
method.Invoke(o, New Object() {New String() {"param1"}})
至
method.Invoke(o, Nothing)
和
method.Invoke(Nothing, Nothing)
和
method.Invoke(o, New Object() {})
没有任何帮助,仍然有错误。