【问题标题】:Value of type ... cannot be converted to... 类型的值无法转换为
【发布时间】:2014-05-03 18:58:11
【问题描述】:

每当我尝试运行我的代码时,我都会不断收到以下错误消息。对于可能导致我无法转换的原因有什么建议吗?好像这两种类型是一样的,所以我对这一种有点困惑。

Value of type 'System.Collections.Generic.List(Of CVE)' cannot be converted to 'System.Collections.Generic.List(Of CVE)'

这里发生错误:

Dim cveList As List(Of CVE)
cveList = CVERepository.GetInstance.ReadAllCVEs

这是 CVERepository 类:

Public Class CVERepository

Private Sub New()

End Sub

Public Shared ReadOnly Property GetInstance As CVERepository
    Get
        Static Instance As CVERepository = New CVERepository
        Return Instance
    End Get
End Property

Public Function ReadAllCVEs() As List(Of CVE)
    Dim objAdapter As OleDb.OleDbDataAdapter
    Dim dtCVE As New DataTable()
    Dim strSQL As String
    Dim strConn As String
    Dim dvCVE As DataView

    strConn = ConnectStringBuild()
    strSQL = "Select * From CVE"

    objAdapter = New OleDb.OleDbDataAdapter(strSQL, strConn)
    objAdapter.Fill(dtCVE)
    dvCVE = dtCVE.DefaultView
    Dim cveList As New List(Of CVE)

    'Put it into an object list to make it more managable.
    For index = 0 To dvCVE.Count - 1
        Dim cve As New CVE
        cve.ID = dvCVE(index)("CVEID")
        cve.PublishedDate = dvCVE(index)("PublishedDate")
        cve.Availability = dvCVE(index)("Availability")
        cve.CVSSScore = dvCVE(index)("CVSSScore")
        cve.Confidentiality = dvCVE(index)("Confidentiality")
        cve.Integrity = dvCVE(index)("Integrity")
        cve.Summary = dvCVE(index)("Summary")
        cveList.Add(cve)
    Next

    Return cveList

End Function

Public Shared Function ConnectStringBuild() As String
    'Grabbing connection string from web.config
    Return System.Configuration.ConfigurationManager.ConnectionStrings("CVEConnectionString").ConnectionString
End Function

End Class

对错误有什么建议吗?

【问题讨论】:

  • 安德鲁 - 你是对的。我正在使用 ASP.net 并创建了一个 CVE.aspx 页面,该页面自动创建了一个 CVE 对象。因此,我之前创建的 CVE 类产生了冲突。

标签: asp.net vb.net


【解决方案1】:

只是一点点改变

Dim cveList As List(Of CVE)
cveList.AddRange(CVERepository.GetInstance.ReadAllCVEs)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多