Cannot find SHA256CryptoServiceProvider for invoke code in studio

I tried using invoke code method in vb.net using:
Dim Encryptor As New System.Security.Cryptography.SHA256CryptoServiceProvider

But my code gives me an error :

“message”: "Invoke Code: No compiled code to run\nerror BC31424: Type ‘System.Security.Cryptography.SHA256CryptoServiceProvider’ in assembly ‘Invoke Code c9098260-1ad7-427b-b5dc-6d52a1194a95, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null’ has been forwarded to assembly ‘System.Security.Cryptography.Csp, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’. Either a reference to ‘System.Security.Cryptography.Csp, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ is missing from your project or the type ‘System.Security.Cryptography.SHA256CryptoServiceProvider’ is missing from assembly ‘System.Security.Cryptography.Csp, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’.

Hi,

SHA256CryptoServiceProvider is obsoleted in .net6.

Can you try to use HashAlgorithm class?

Dim ha As System.Security.Cryptography.HashAlgorithm = System.Security.Cryptography.SHA256.Create()
Dim result as byte() = ha.ComputeHash(System.Text.Encoding.UTF8.GetBytes("test"))

Regards,

I encountered another error : No compiled code to run
error BC30456: ‘ComputeHash’ is not a member of ‘Byte()’.

Did you create HashAlgorithm instance?
The above ha is HashAlgorithm type.

Or Can you share your code?

Regards,

Dim ha As System.Security.Cryptography.HashAlgorithm = System.Security.Cryptography.SHA256.Create()
Dim res As Byte() = ha.ComputeHash(System.Text.Encoding.UTF8.GetBytes(“test”))
'Dim Encryptor As New System.Security.Cryptography.SHA256CryptoServiceProvider

’ Create a fileStream For the file.
Dim fileStream As FileStream = File.OpenRead(FilePath)
’ Be sure it’s positioned to the beginning of the stream.
fileStream.Position = 0

’ Compute the hash code for the fileStream
Dim bytesToHash() As Byte = res.ComputeHash(fileStream)

’ Close the fileStream
fileStream.Close()

’ Convert the hash bytes to user-friendly text
For Each item As Byte In bytesToHash
Result += item.ToString(“x2”)
Next

Hi,

At line 11, res variable is byte array and it causes this error. Probably it should be ha.

Regards,

1 Like

The code’s error was gone, however I was prompted with the same error after execution:

{
“message”: “Invoke Code: No compiled code to run\nerror BC31424: Type ‘System.Security.Cryptography.HashAlgorithm’ in assembly ‘?, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null’ has been forwarded to assembly ‘System.Security.Cryptography.Primitives, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’. Either a reference to ‘System.Security.Cryptography.Primitives, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ is missing from your project or the type ‘System.Security.Cryptography.HashAlgorithm’ is missing from assembly ‘System.Security.Cryptography.Primitives, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’. At line 1\r\nerror BC30456: ‘SHA256’ is not a member of ‘System.Security.Cryptography’. At line 1\r\n”,
“level”: “Error”,
“logType”: “Default”,
“timeStamp”: “10:02:23”,
“fileName”: “Invoke Code”,
“processVersion”: “1.0.0”,
“jobId”: “e3392a30-e006-4373-8e91-c87df99632f1”,
“robotName”: “akansha.rawat@in.ey.com-attended”,
“machineId”: 3310335,
“organizationUnitId”: 4666130
}

HI,

Can you share your project as a zip file,if possible?

Regards,

Invoke Method and Code.zip (4.5 KB)
in this invoke code workflow

Hi,

In my environment (23.4.2) , it works well as the following.( I upgraded System.Activites package to the stable latest because there is no this package of 21.10.x. version for my environment)

Regards,

it worked, thank you Yoichi!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.