2010-11-04 22 views
0

Je ne sais pas où je pense.Casting de x509 à x5092

Voici ma propriété

''' <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 

et Heres où il est dit im faire la distribution illégale:

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

Pourquoi est-il dit cela? Tout est défini dans le bon type mais il pense toujours que je lance.

Répondre

1

CreateFromCertFile génère l'ancien type d'objet. Utilisez cette méthode, mais utilisez le constructeur X509Certificate2 pour effectuer le cast.

0

Le code vb.net:

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

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