Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problem with Array and Reflection
Message
From
14/12/2006 18:01:39
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
VB 8.0
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01176405
Message ID:
01177830
Views:
6
>Sure you can. Look at the InnerException of the returned Exception. Somewhere in the Exception stack is the real error...
>
>Most likely it's:
>
>You're calling a method that has overloads (in which case you have to pass the parameter types as a type array)
>You don't have permissions to access the method
>The object returned is null in your code <s>

I have simplified it like this. It no longer passes parameters to the method and it is much faster.
    ' expO1 Data provider
    Private Function ProcessTaskQuery(ByVal toDataProvider As Framework.Framework.Data) As Boolean
        Dim lcClass As String = ""
        Dim lcMethod As String = ""
        Dim lnCounter As Integer = 0
        Dim loAssembly As System.Reflection.Assembly
        Dim loMethod As System.Reflection.MethodInfo
        Dim loObject As Object
        Dim loParameterClass(1) As Object
        Dim loRow As DataRow
        Dim loType As System.Type

        loParameterClass(0) = oApp
        loParameterClass(1) = Me

        ' Establish the reference to the EXE
        loAssembly = System.Reflection.Assembly.LoadFrom(oApp.cStartupDirectory + "Robot.exe")

        ' Scan each task to execute
        For lnCounter = 0 To toDataProvider.nCount - 1
            loRow = toDataProvider.oDataSet.Tables("Temp").Rows(lnCounter)
            Status.Text = "Processing " + Trim(loRow("Title")) + "..."
            lcClass = Trim(loRow("Class"))
            lcMethod = Trim(loRow("Method"))
            Try

                ' Get a reference to the class
                loType = loAssembly.GetType("Robot." + lcClass)
                loObject = Activator.CreateInstance(loType, loParameterClass)

                ' Get a reference to the method
                loMethod = loObject.GetType().GetMethod(lcMethod)

                ' Call the method
                loMethod.Invoke(loObject, Nothing)

            Catch loError As Exception
                oApp.ErrorSetup(loError)
                Return False
            End Try
        Next

        Return True
    End Function
However, when I have an error in one of the methods called, I still have a generic error message:

"Exception has been thrown by the target of an invocation."

The stack is as followed:

at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Robot.Main.ProcessTaskQuery(Data toDataProvider)

There isn't much there to help me in the stack information.

There is no overload in this design. As for the permissions, I do not know what you mean. If there is no error in the method, the code executes ok. But, if there is an error, do you mean I need to setup permission somewhere as this design would require it in order for me to obtain relevant information on the error? As for the object returned is null, this is usually when the object cannot be created. In this case, all the objects are properly created.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Previous
Reply
Map
View

Click here to load this message in the networking platform