title: Casting private key to RSACryptoServiceProvider not working
body: <p>I have a X509Certificate2 variable and I'm trying to cast the private key of the variable to a RSACryptoServiceProvider</p>
  
  <pre><code>RSACryptoServiceProvider pkey = (RSACryptoServiceProvider)cert.PrivateKey;
  </code></pre>
  
  <p>However I get this exception.</p>
  
  <blockquote>
    <p>System.InvalidCastException: 'Unable to cast object of type 'System.Security.Cryptography.RSACng' to type 'System.Security.Cryptography.RSACryptoServiceProvider'.'</p>
  </blockquote>
  
  <p>It's weird that this happens because other answers in SO suggested the same procedure as mine but I get an exception. Any solutions to this?</p>