2010-11-04 28 views
0

我不知道它在哪裏認爲我在鑄造。從x509鑄造到x5092

這裏是我的財產

''' <summary> 
     ''' Gets the GetX509Certificate from a file. 
     ''' </summary> 
     Private ReadOnly Property GetX509Certificate() As X509Certificate2 
      Get 
       If m_X509Certificate Is Nothing Then 
        'Should be able to use any of the "Create" methods in the namespace. 
        Dim path As String = "C:\Development\Workspaces\Productivity Framework\V07\Akcelerant.Connector.RouteOne.Web\Test.cer" 
        m_X509Certificate = X509Certificate2.CreateFromCertFile(path) 
       End If 
       If m_X509Certificate Is Nothing Then 
        Throw New ApplicationException("Certificate not found") 
       End If 
       Return m_X509Certificate 
      End Get 
     End Property 

和繼承人那裏說即時通訊做非法投:

Dim cert As System.Security.Cryptography.X509Certificates.X509Certificate2 = Me.GetX509Certificate 

爲什麼說?一切都以正確的類型定義,但它仍然認爲我正在投射。

回答

1

CreateFromCertFile生成舊的對象類型。使用此方法,但使用X509Certificate2構造函數進行強制轉換。

0

的vb.net代碼:

dim certificatePath as String = "c:\cert.cer" 

Dim cert As X509Certificate2 = New X509Certificate2(X509Certificate.CreateFromCertFile(certificatePath))