0

我有两个不同的 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

返回 Nothing 的第二个是:

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

谁能帮我理解为什么第一个工作正常,第二个什么也没返回。

4

2 回答 2

0

看起来您在 args() 中有另一个参数,您是否验证了那里的变量类型匹配,并且实际上有一个构造函数接受这 4 个 args?

于 2011-10-11T12:28:55.940 回答
0

移自评论:

我从您更新的代码中看到“FXWB.BSRPT”和 ItemName 不是您的类,而是一些第三方组件,对吗?然后,您应该查阅有关此组件的文档或联系其作者以获取有关您的代码无法正常工作的信息。

于 2011-10-11T18:05:54.517 回答