Invoke Code Activity errors

Hello everyone,
I got C# code but when I type it on Invoke Code activity but it’s not working but errors,
Do I need some packages for coding or imports?

Hi @Temuulen_Buyangerel

No need to install any packages, may be there is an error in your code. Give the proper code in Invoke code activity. It will works.

Or Share the error what you are getting in Invoke code activity.

Hope it helps!!

Error ERROR Validation Error No compiled code to run
error CS0106: The modifier ‘public’ is not valid for this item At line 1
error CS1001: Identifier expected At line 1
error CS1003: Syntax error, ‘,’ expected At line 1
error CS1001: Identifier expected At line 1
error CS1525: Invalid expression term ‘string’ At line 3
error CS1525: Invalid expression term ‘string’ At line 3
error CS1525: Invalid expression term ‘string’ At line 8
error CS1525: Invalid expression term ‘string’ At line 11
error CS0106: The modifier ‘private’ is not valid for this item At line 20
error CS1061: ‘string’ does not contain a definition for ‘equals’ and no accessible extension method ‘equals’ accepting a first argument of type ‘string’ could be found (are you missing a using directive or an assembly reference?) At line 3
error CS0246: The type or namespace name ‘Cipher’ could not be found (are you missing a using directive or an assembly reference?) At line 4
error CS0103: The name ‘Cipher’ does not exist in the current context At line 4
error CS0246: The type or namespace name ‘SecretKeySpec’ could not be found (are you missing a using directive or an assembly reference?) At line 5
error CS0246: The type or namespace name ‘SecretKeySpec’ could not be found (are you missing a using directive or an assembly reference?) At line 5
error CS0103: The name ‘StandardCharsets’ does not exist in the current context At line 5
error CS1061: ‘string’ does not contain a definition for ‘getBytes’ and no accessible extension method ‘getBytes’ accepting a first argument of type ‘string’ could be found (are you missing a using directive or an assembly reference?) At line 5
error CS0246: The type or namespace name ‘IvParameterSpec’ could not be found (are you missing a using directive or an assembly reference?) At line 6
error CS0246: The type or namespace name ‘IvParameterSpec’ could not be found (are you missing a using directive or an assembly reference?) At line 6
error CS0103: The name ‘StandardCharsets’ does not exist in the current context At line 6
error CS1061: ‘string’ does not contain a definition for ‘getBytes’ and no accessible extension method ‘getBytes’ accepting a first argument of type ‘string’ could be found (are you missing a using directive or an assembly reference?) At line 6
error CS0103: The name ‘getBytesFromString’ does not exist in the current context At line 8
error CS0103: The name ‘StandardCharsets’ does not exist in the current context At line 9
error CS1503: Argument 1: cannot convert from ‘byte’ to ‘char’ At line 9
error CS1061: ‘Exception’ does not contain a definition for ‘printStackTrace’ and no accessible extension method ‘printStackTrace’ accepting a first argument of type ‘Exception’ could be found (are you missing a using directive or an assembly reference?) At line 14
error CS1061: ‘string’ does not contain a definition for ‘equals’ and no accessible extension method ‘equals’ accepting a first argument of type ‘string’ could be found (are you missing a using directive or an assembly reference?) At line 21
error CS0103: The name ‘Base64’ does not exist in the current context At line 21
error CS0103: The name ‘StandardCharsets’ does not exist in the current context At line 21
error CS0103: The name ‘Hex’ does not exist in the current context At line 21 Main.xaml

Share your code once… @Temuulen_Buyangerel

Here is the code
public static String getDecryption(String type, String string, String sessionKey, String ivKey) {
try {
if (string != null && !“”.equals(string)) {
Cipher cipher = Cipher.getInstance(“AES/CBC/PKCS5PADDING”);
SecretKeySpec keySpec = new SecretKeySpec(sessionKey.getBytes(StandardCharsets.UTF_8), “AES”);
IvParameterSpec ivParameterSpec = new IvParameterSpec(ivKey.getBytes(StandardCharsets.UTF_8));
cipher.init(2, keySpec, ivParameterSpec);
byte bytePlainText = cipher.doFinal(getBytesFromString(type, string));
return new String(bytePlainText, StandardCharsets.UTF_8);
} else {
return string;
}
} catch (Exception var8) {
var8.printStackTrace();
return null;
}
}

private static String getStringFromBytes(String type, byte bytes) {
return type.equals(“base64”) ? new String(Base64.getEncoder().encode(bytes), StandardCharsets.UTF_8) : Hex.encodeHexString(bytes);
}

The above code looks likes Java not C#. Could you check your code once… @Temuulen_Buyangerel

Okay, How do I make it on Java sir?

You can’t use the java code in Invoke code activity… @Temuulen_Buyangerel

Is there other ways to invoke java method?

@Yoichi Can you help me if you got some time please.

Hi @Temuulen_Buyangerel

You can Install Java Packages i.e UiPath.Java.Activites

Watch this video for How to use the activity of these packages

How to integrate Java code in UiPath? Java Activities Pack to harness the power of Java code |UiPath (youtube.com)

1 Like

Thank you!
I appreciate it

1 Like

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