0

私は 2 つの異なる GetConstructors() を持っています。1 つは返すべきものを返していますが、もう 1 つは何も返していません。

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 を返す 2 番目は次のとおりです。

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

最初のものは機能し、2番目のものは何も返さない理由を誰かが理解するのを手伝ってくれますか?

4

2 に答える 2

0

It looks like you have another argument in args(), have you verified that the types of the variables you have there match up, and there is actually a constructor which takes those 4 args?

于 2011-10-11T12:28:55.940 に答える
0

コメントから移動:

更新されたコードから、「FXWB.BSRPT」と ItemName はクラスではなく、サードパーティのコンポーネントであることがわかりますよね? 次に、このコンポーネントのドキュメントを参照するか、その作成者に連絡して、コードが機能しない理由に関する情報を入手してください。

于 2011-10-11T18:05:54.517 に答える