Question Exception Thrown By Target of Invocation Error (only as stand-alone not in test)

TheRealMcD

New member
Joined
Feb 20, 2012
Messages
3
Programming Experience
10+
I have an application that provides the users a list of crystal reports that they can run.
I use a datatable, displayed on a datagrid within a form, to show the users descriptive names for the reports, and a check box for each.
The users clicks the check box for the report(s) they want to run. (I also have select All, deselect all, etc.. )

The users then clicks a "OK" button and then I do a For each ... loop through the datatable to determine the reports selected.

Within a Public Class, in a different but included .vb file, I have a sub for each of the reports within the list and there is a field within the datatable that has the exact name of the sub I want to call.

The subs generate the data and call the desired crystal report.

On my development machine the application works perfectly within the Visual Studio 2008 test environment, and also after I build, publish, and then run it from explorer or wherever.

However, when I run in on another machine. It fails to invoke the subs within the public class. Everything else work fine. I did the old fashioned method of putting msgbox comments in every section
and determined it fails when I try to invoke the sub.

Like I said, it works on my development machine. My development machine is Windows 7 64bit, and the target machine is Windows 7 32bit but the compiler settings is set to any machine so that should not make
a difference right?

Any help will be appreciated

Thank You

Public Sub RunRept(ByVal ReptName As String, ByVal ReptMode As Int16, ByVal cs As SqlConnection, ByRef ds_cklst As DataSet, _
ByVal mo As Int16, ByVal yr As Int16, ByVal ReptID As String, ByVal PDF_PTH As String, ByVal PDF_CR_PTH As String, ByVal Prnter As String)

Dim Reptobj As New ReptCall
Dim myType As System.Type = GetType(ReptCall)
Dim myInfo As System.Reflection.MethodInfo = myType.GetMethod(ReptName)
Dim myParams() As Object = {ReptMode, cs, ds_cklst, mo, yr, ReptID, PDF_PTH, PDF_CR_PTH, Prnter}

Try

Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Sales Analysis")

End Try

Try
myInfo.Invoke(Reptobj, myParams)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Sales Analysis")
End Try

End Sub
 
I am new to Visual Studio. So, can you give me some tips on how to catch the inner exception. The code never reaches beyond the invocation and does not have an error when it run on my development machine.

The Try.. Catch I have around the wrapper is not doing the job.
 
The inner exception is available to read from the InnerException property of the TargetInvocationException that you caught.
It would be a good idea to follow recommendations and be more specific in your exception handling, that means handle TargetInvocationException rather than the general Exception when you expect and actually can handle it.
 

Latest posts

Back
Top