Cannot find type "System.Security.Cryptography.AesCryptoServiceProvider"

Hi ,

We are getting the below error. we are running 3.1.4 tentacles.
It is strange that the error below is only for UAT and PROD environments and not for the Dev or Integration test.

New-Object : Cannot find type [System.Security.Cryptography.AesCryptoServicePro
12:31:51Error
vider]: make sure the assembly containing this type is loaded.
12:31:51Error
At C:\Octopus\Work\20160908003149-395\Bootstrap.Script.ps1:69 char:24
12:31:51Error

  • $provider = new-Object <<<<  System.Security.Cryptography.AesCryptoServic
    

12:31:51Error
eProvider
12:31:51Error
+ CategoryInfo : InvalidType: (:slight_smile: [New-Object], PSArgumentExcepti
12:31:51Error
on
12:31:51Error
+ FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewOb
12:31:51Error
jectCommand
12:31:51Error
12:31:51Error
Property ‘Mode’ cannot be found on this object; make sure it exists and is sett
12:31:51Error
able.
12:31:51Error
At C:\Octopus\Work\20160908003149-395\Bootstrap.Script.ps1:70 char:12
12:31:51Error

  • $provider. <<<< Mode = [System.Security.Cryptography.CipherMode]::CBC
    

12:31:51Error
+ CategoryInfo : InvalidOperation: (Mode:String) [], RuntimeExcep
12:31:51Error
tion
12:31:51Error
+ FullyQualifiedErrorId : PropertyNotFound
12:31:51Error
12:31:51Error
Property ‘Padding’ cannot be found on this object; make sure it exists and is s
12:31:51Error
ettable.
12:31:51Error
At C:\Octopus\Work\20160908003149-395\Bootstrap.Script.ps1:71 char:12
12:31:51Error

  • $provider. <<<< Padding = [System.Security.Cryptography.PaddingMode]::PKC
    

12:31:51Error
S7
12:31:51Error
+ CategoryInfo : InvalidOperation: (Padding:String) [], RuntimeEx
12:31:51Error
ception
12:31:51Error
+ FullyQualifiedErrorId : PropertyNotFound
12:31:51Error
12:31:51Error
Property ‘KeySize’ cannot be found on this object; make sure it exists and is s
12:31:51Error
ettable.
12:31:51Error
At C:\Octopus\Work\20160908003149-395\Bootstrap.Script.ps1:72 char:12
12:31:51Error

  • $provider. <<<< KeySize = 128
    

12:31:51Error
+ CategoryInfo : InvalidOperation: (KeySize:String) [], RuntimeEx
12:31:51Error
ception
12:31:51Error
+ FullyQualifiedErrorId : PropertyNotFound
12:31:51Error
12:31:51Error
Property ‘BlockSize’ cannot be found on this object; make sure it exists and is
12:31:51Error
settable.
12:31:51Error
At C:\Octopus\Work\20160908003149-395\Bootstrap.Script.ps1:73 char:12
12:31:51Error

  • $provider. <<<< BlockSize = 128
    

12:31:51Error
+ CategoryInfo : InvalidOperation: (BlockSize:String) [], Runtime
12:31:51Error
Exception
12:31:51Error
+ FullyQualifiedErrorId : PropertyNotFound
12:31:51Error
12:31:51Error
Property ‘Key’ cannot be found on this object; make sure it exists and is setta
12:31:51Error
ble.
12:31:51Error
At C:\Octopus\Work\20160908003149-395\Bootstrap.Script.ps1:74 char:12
12:31:51Error

  • $provider. <<<< Key = [System.Convert]::FromBase64String($key)
    

12:31:51Error
+ CategoryInfo : InvalidOperation: (Key:String) [], RuntimeExcept
12:31:51Error
ion
12:31:51Error
+ FullyQualifiedErrorId : PropertyNotFound
12:31:51Error
12:31:51Error
Property ‘IV’ cannot be found on this object; make sure it exists and is settab
12:31:51Error
le.
12:31:51Error
At C:\Octopus\Work\20160908003149-395\Bootstrap.Script.ps1:75 char:12
12:31:51Error

  • $provider. <<<< IV =[System.Convert]::FromBase64String($iv)
    

12:31:51Error
+ CategoryInfo : InvalidOperation: (IV:String) [], RuntimeExcepti
12:31:51Error
on
12:31:51Error
+ FullyQualifiedErrorId : PropertyNotFound
12:31:51Error
12:31:51Error
You cannot call a method on a null-valued expression.
12:31:51Error
At C:\Octopus\Work\20160908003149-395\Bootstrap.Script.ps1:77 char:34
12:31:51Error

  • $dec = $provider.CreateDecryptor <<<< ()
    

12:31:51Error
+ CategoryInfo : InvalidOperation: (CreateDecryptor:String) [], R
12:31:51Error
untimeException
12:31:51Error
+ FullyQualifiedErrorId : InvokeMethodOnNull
12:31:51Error
12:31:51Error
Exception calling “ReadToEnd” with “0” argument(s): "Object reference not set t
12:31:51Error
o an instance of an object."
12:31:51Error
At C:\Octopus\Work\20160908003149-395\Bootstrap.Script.ps1:81 char:29
12:31:51Error

  •     Write-Output $sr.ReadToEnd <<<< () 
    

12:31:51Error
+ CategoryInfo : NotSpecified: (:slight_smile: [], MethodInvocationException
12:31:51Error
+ FullyQualifiedErrorId : DotNetMethodException

Hi Daniel,

Thanks for getting in touch! The AesCryptoServiceProvider we are trying to load is only present on machines with .NET 3.5+, is it possible that your UAT and PROD environments are on older servers without this installed?

Also, can I ask what version your Octopus Server is at? Is it 3.1.4 as well? The component causing this error (Calamari) is streamed down to the Tentacle on each deploy, so it gets upgraded with the server version even if the Tentacles are on older versions. Octopus Server versions 3.2.7+ should handle this correctly and fall back to another Crypto Provider.

Hope that helps!

Mark

Hi Mark,

Thanks for your email.
We have .net 4.5.2 installed across all servers consistently.
Yes we have 3.1.4 as the octopus server.
[cid:image001.png@01D20AAF.642BEAC0]

Do you think we should upgrade to 3.2.7?

It makes it interesting as it works on SysTest environments.
And in UAT and PROD it fails only when there is step that requires to use the encrypted passwords.

Regards,
Daniel

image001.png

Hi Daniel,

It makes sense that you only see this on steps that use encrypted passwords, as we are loading this to handle the decryption.

What is probably happening is that the machines this failed on only have Powershell 2.0. PS 2.0 can only use .NET 2.0-3.5.1, so if you have installed 4.5.2, but not 3.5.1, it will be using .NET 2.0 to run, which is why we’re seeing the problem. If that’s the case you have three options:

  1. Install Powershell 3.0+, which will use CLR 4.0.
  2. Stick to PS 2.0, but install .NET 3.5.1
  3. Upgrade Octopus to a version newer than 3.2.7. I would recommend the newest version you are licensed for. You can check Maintenance Expires date in Configuration -> License, then provided you had a licence when 3.x.0 was released, you are licensed for all versions of 3.x. The latest versions are 3.2.24, 3.3.27 and 3.4.6. We recommend that you take a backup of your Octopus database before updating.

Hope that helps.

Mark

Thanks Mark,
Sorry for the delay.
We are to try the first two options in UAT and let you know the results.

Cheers,
Daniel