I am having a problem returning a value from an invoked method. The class I'm instantiating is as follows:
The app that calls this function looks like the following:
The error I get is "System.Reflection.TargetParameterCountException". When I change my method to a sub and just call the Invoke function without attempting to return anything it executes fine. I feel there's something obvious eluding me here. Thanks for any suggestions.
Code:
Public Class DoItClass
Public Function GetAValue(ByVal p_intType As Integer, ByRef p_strWhichType As String) As String
Select Case p_intType
Case 1
p_strWhichType = "One"
Case 2
p_strWhichType = "Two"
End Select
Return "GetAValue was accessed"
End Function
End Class
The app that calls this function looks like the following:
Code:
dim strMethodName As String = "GetAValue"
dim strClassName As string = "DoItClass"
Dim objAssembly As Assembly
Dim objClass As Object
Dim objType As Type
Dim objMethod As MethodInfo
Dim objParamArray() As Object = {1,""}
Dim strReturnMessage As String
try
objAssembly = Assembly.LoadFrom("C:\MyDynamicClass.dll")
For Each objType In objAssembly.GetTypes
If objType.FullName.EndsWith("." + strClassName) Then
objClass = objAssembly.CreateInstance(objType.FullName.ToString)
objMethod = objType.GetMethod(strMethod)
strReturnMessage = CType(objMethod.Invoke(objClass, objParamArray), String)
strByRefParm = objParamArray(1).ToString
exit for
End If
Next
Catch ex as Exception
Messagebox.show(ex.message)
End Try
The error I get is "System.Reflection.TargetParameterCountException". When I change my method to a sub and just call the Invoke function without attempting to return anything it executes fine. I feel there's something obvious eluding me here. Thanks for any suggestions.