Unable to execute c# code in uipath invoke activity

Hi Team,

I am trying to invoke c sharp code in invoke activity.
System.Windows.Forms.MessageBox.Show(“Hello from UiPath!”);

But I am getting below error.
Invoke Code: No compiled code to run
error CS0234: The type or namespace name ‘MessageBox’ does not exist in the namespace ‘System.Windows.Forms’ (are you missing an assembly reference?) At line 1

Please assist.

Regards,
rds

The error message is pretty clear.

Are you typing the expression out, or pasting it in? You need to type it out so that the imports are done correctly.

Thanks Paul. But I am typing that.

System.Windows.Forms namespace, which contains the MessageBox class, is not accessible from your Invoke Code activity. You can resolve this issue by explicitly adding a reference to the System.Windows.Forms assembly in your Invoke Code activity.

Here’s how to do it:

1.Open the Invoke Code activity in UiPath.

2.In the Properties panel on the right, locate the “Imports” section.

3.Click on the “Add Imports” link.

4.In the dialog that appears, enter “System.Windows.Forms” in the “Namespace” field.

5.Click the “Add” button.

6.Now, you should see “System.Windows.Forms” listed under the “Imports” section in the Properties panel.

  1. You can use MessageBox.Show("Hello from UiPath!"); in your Invoke Code block without any errors.

@rds0511

Thanks Praveen. But I already imported that namespace. still same error.

Try once this In the “Invoke Code” activity properties, in the “Code” field, add your C# code

System.Windows.Forms.MessageBox.Show(“Hello from UiPath!”);

@rds0511

Might be other issue follow this steps

1.Check Imports: Make sure the using System.Windows.Forms; statement is at the beginning of your C# code within the “Invoke Code” activity. It should be before any other code.

  1. Restart UiPath:Sometimes, UiPath Studio might not pick up new assembly references immediately. Try restarting UiPath to see if the issue persists.

3.Ensure that the “Invoke Code” activity is placed in a sequence where it can be executed in the correct order. The error could be related to the sequence of execution in your workflow.

4.Close and reopen your UiPath project to refresh any cached information.
@rds0511

Still same error Praveen.

Can you try to Reinstall System.Windows.Forms Package: Sometimes, package references can become corrupted. Try removing the System.Windows.Forms package from your UiPath project, save your project, and then re-add it. Ensure that the package is installed correctly

Studio Update : Ensure you’re using the latest version of UiPath Studio. Older versions may have compatibility issues with certain libraries.

@rds0511

I am using latest version of UiPath. As you mentioned I reinstalled package. But same error.