首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GetConstructor什么也不返回

GetConstructor什么也不返回
EN

Stack Overflow用户
提问于 2011-10-10 16:46:09
回答 2查看 547关注 0票数 0

我有两个不同的GetConstructors(),一个是返回它应该返回的东西,另一个是什么也不返回。

BSRPTReportPerformanceSubcontractorRating是ItemName

第一个返回它应该正确的内容的是:

代码语言:javascript
复制
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

第二个什么也不回的是:

代码语言:javascript
复制
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

有人能帮我理解为什么第一个在工作,第二个却什么也没回。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-10-11 18:05:54

摘自评论:

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

票数 0
EN

Stack Overflow用户

发布于 2011-10-11 12:28:55

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7716020

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档