Cannot load Security.Cryptography.X509Certificates.RSACertificateExtensions

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
ErnieB
Posts: 56
Last visit: Mon Dec 19, 2022 2:09 am

Cannot load Security.Cryptography.X509Certificates.RSACertificateExtensions

Post by ErnieB »

Hello

can someone please help me with the following (perhaps I am missing a DLL)
One Windows 2012 R2 I need to load Security.Cryptography.X509Certificates.RSACertificateExtensions part as part of a larger PowerShell script

I get the standard message

Add-Type -AssemblyName Security.Cryptography.X509Certificates.RSACertificateExtensions

Add-Type : Cannot add type. The assembly 'Security.Cryptography.X509Certificates.RSACertificateExtensions' could not be found.
At line:1 char:1
+ Add-Type -AssemblyName Security.Cryptography.X509Certificates.RSACert ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Security.Crypto...icateExtensions:String) [Add-Type], Exception
+ FullyQualifiedErrorId : ASSEMBLY_NOT_FOUND,Microsoft.PowerShell.Commands.AddTypeCommand

Add-Type : Cannot add type. One or more required assemblies are missing.
At line:1 char:1
+ Add-Type -AssemblyName Security.Cryptography.X509Certificates.RSACert ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Add-Type], InvalidOperationException
+ FullyQualifiedErrorId : ASSEMBLY_LOAD_ERRORS,Microsoft.PowerShell.Commands.AddTypeCommand

I assume I am missing a DLL

on my Windows 10 PC I can do the following OK

[Security.Cryptography.X509Certificates.RSACertificateExtensions] | gm

if I try this on my Windows 2012 R2 Server I get the error

PS C:\> [Security.Cryptography.X509Certificates.RSACertificateExtensions] | gm
Unable to find type [Security.Cryptography.X509Certificates.RSACertificateExtensions]. Make sure that the assembly that contains this type is loaded.
At line:1 char:2
+ [Security.Cryptography.X509Certificates.RSACertificateExtensions] | gm
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Security.Crypto...icateExtensions:TypeName) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound


Please advise as I need to use this namespace and its methods when running my script on a Windows 2012 R2 Server

Thanks
Ernest
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Cannot load Security.Cryptography.X509Certificates.RSACertificateExtensions

Post by jvierra »

You do not need to load the assembly. this is not an assembly, it is a type. Just reference it:

[Security.Cryptography.X509Certificates.RSACertificateExtensions][/b}

It may be that you are missing Net 4.6 which is an optional install on 2012r2
See: https://msdn.microsoft.com/en-us/librar ... .110).aspx
This topic is 6 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked