Due to certain circumstances I have to call a function from Project A in Project B via reflection.
The signature of the method to be called looks like this:
public function Copy(ByRef MainForm as RibbonForm, ID_Source as INT, BYREF ID_new as int) AS BOOLEAN
...
END FUNCTION
The call in Project B to this function is as following:
Private Sub F_Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ID_VERTRAG_SOURCE As Integer = 2101
Dim ID_VERTRAG_DEST As Integer = 0
Dim RibbonForm As RibbonForm
'V2
Dim Assembly As Assembly = Assembly.LoadFrom("*PATH TO EXE*")
AppDomain.CurrentDomain.Load(Assembly.GetName())
Dim t As Type = Assembly.GetType("*CLASS NAME*")
Dim dynamicInstance As Object = Activator.CreateInstance(t)
RibbonForm = New RibbonForm
Dim classInstance As Object = Activator.CreateInstance(t)
Dim p As Object() = {RibbonForm, ID_VERTRAG_SOURCE, ID_VERTRAG_DEST}
Dim methodInfo As MethodInfo = t.GetMethod("Copy")
Dim result = methodInfo.Invoke(classInstance, p)
End Sub
When trying to invoke the method i get the following exception:
The Object of Type "DevExpress.XtraBars.Ribbon.RibbonForm" cannot be converted to type "DevExpress.XtraBars.Ribbon.RibbonForm&". bei System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast) bei System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr) bei System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig) bei System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) bei System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
bei System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) bei LNG_Indexanpassung_addon.Form1.F_Main_Load(Object sender, EventArgs e) in *****\Form1.vb:Zeile 25. bei System.EventHandler.Invoke(Object sender, EventArgs e) bei System.Windows.Forms.Form.OnLoad(EventArgs e) bei System.Windows.Forms.Form.OnCreateControl() bei System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
bei System.Windows.Forms.Control.CreateControl() bei System.Windows.Forms.Control.WmShowWindow(Message& m) bei System.Windows.Forms.Control.WndProc(Message& m) bei System.Windows.Forms.ScrollableControl.WndProc(Message& m) bei System.Windows.Forms.Form.WmShowWindow(Message& m) bei System.Windows.Forms.Form.WndProc(Message& m) bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Aucun commentaire:
Enregistrer un commentaire