我有两个不同的GetConstructors(),一个是返回它应该返回另一个但是什么都没有返回。
ItemName是 BSRPTReportPerformanceSubcontractorRating
第一个正确返回的应该是:
Shared Function Invoke(ByVal Page As FXWBPage, ByVal ItemName As String, ByVal intFolderID As Integer, ByVal strItemID As String, ByVal strDummy As String) As BSRPTPrint
Dim objPrint As BSRPTPrint
Dim objConstructor As System.Reflection.ConstructorInfo
Dim objType As Type
Dim strType As String = "FXWB.BSRPT" & ItemName
Dim types() As Type = {GetType(FXWBPage), GetType(Integer), GetType(String)}
Dim args() As Object = {Page, intFolderID, strItemID}
Try
Try
objType = Type.GetType(strType, True)
Catch ex As Exception
Throw New Exception("Cannot reflect type """ & strType & """. Check Request parameter ""PrintItem"", it must take the name of correspondig BSRPT class without BSRPT prefix", ex)
End Try
objConstructor = objType.GetConstructor(types)
If objConstructor Is Nothing Then
Throw New Exception("Cannot invoke type """ & objType.ToString() & """. Check constructor parameter, it must be of FXWBPage type and not passed by ref.")
End If
Try
objPrint = objConstructor.Invoke(args)
Catch exep As Exception
Throw New Exception("Cannot load report """ & strType & """. Error: " & exep.Message)
End Try
Try
objPrint.DataBind()
Catch ex As Exception
Throw New Exception("Error occured on data binding level. Report """ & strType & """.", ex)
End Try
Catch ex As Exception
Throw ex
End Try
Return objPrint
End Function
第二个没有返回的是:
Shared Function Invoke(ByVal Page As FXWBPage, ByVal ItemName As String, ByVal intFolderID As Integer, ByVal intProjectID As Integer, ByVal strDummy As String, ByVal intSubcontractorID As Integer) As BSRPTPrint
Dim objPrint As BSRPTPrint
Dim objConstructor As System.Reflection.ConstructorInfo
Dim objType As Type
Dim strType As String = "FXWB.BSRPT" & ItemName
Dim types() As Type = {GetType(FXWBPage), GetType(Integer), GetType(Integer), GetType(String), GetType(Integer)}
Dim args() As Object = {Page, intFolderID, intProjectID, intSubcontractorID}
Try
Try
objType = Type.GetType(strType, True)
Catch ex As Exception
Throw New Exception("Cannot reflect type """ & strType & """. Check Request parameter ""PrintItem"", it must take the name of correspondig BSRPT class without BSRPT prefix", ex)
End Try
objConstructor = objType.GetConstructor(types)
If objConstructor Is Nothing Then
Throw New Exception("Cannot invoke type """ & objType.ToString() & """. Check constructor parameter, it must be of FXWBPage type and not passed by ref.")
End If
Try
objPrint = objConstructor.Invoke(args)
Catch exep As Exception
Throw New Exception("Cannot load report """ & strType & """. Error: " & exep.Message)
End Try
Try
objPrint.DataBind()
Catch ex As Exception
Throw New Exception("Error occured on data binding level. Report """ & strType & """.", ex)
End Try
Catch ex As Exception
Throw ex
End Try
Return objPrint
End Function
任何人都可以帮助我理解为什么第一个正在工作而第二个没有返回任何东西。
答案 0 :(得分:0)
看起来你在args()中有另一个参数,你是否已经验证了你所拥有的变量的类型是否匹配,并且实际上有一个构造函数需要那些4个参数?
答案 1 :(得分:0)
从评论中移出:
我从您更新的代码中看到“FXWB.BSRPT”& ItemName不是你的类,而是一些第三方组件,对吧?然后,您应该查阅有关此组件的文档或与其作者联系,以获取有关代码无法正常工作的信息。