"exception has been thrown by the target of an invocation" on invoke RRS feed

  • Question

  • User1254222884 posted

    I'm getting a really strange error today (after a new build yesterday) of our website. The error is "exception has been thrown by the target of an invocation" and happens on the following line of code: 

    strFunctionValue = Me.GetType.GetMethod(strFunctionName).Invoke(Me, arrParameterValues).ToString

    strFunctionName contains the name of the function to be invoked, arrParameterValues is an array of parameters to pass to the function, then the result of the function has it's ToString method invoked. This worked yesterday. I didn't change any of the code in this particular function (though outside functions may have changed).

    Any idea what might be happening to cause this error?


    Thursday, August 14, 2008 11:47 AM


  • User1254222884 posted

    OK, so I have more info now after single-stepping through the code (once I got it to fail in our test environment).

    The error was happening down in the routine being called by the invoke method and bubbling up to the routine that called invoke. The invoke method was inside a try/catch block like this: 

      'A bunch of setup code to get the function name and parameters
       strFunctionValue = Me.GetType.GetMethod(strFunctionName).Invoke(Me, arrParameterValues).ToString
    Catch ex As System.IO.IOException
       strFunctionValue = ""
    End Try
     Apparently, since the catch wasn't catching the specific error generated, the system defaulted to the somewhat generic error reported. Anyway, I found the error in the invoked routine and fixed it, So it turned out all good....


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 14, 2008 1:50 PM