Can we invoke C # code in Uipath

Hi ,
I am trying to invoke some code using uipath 'invoke code 'activity.
Below is my code:
public class services
public static void StartService(string serviceName)
ServiceController service = new ServiceController(serviceName);

I am getting below error.
No compiled code to run
error CS1513: } expected At line 0
error CS1022: Type or namespace definition, or end-of-file expected At line 13

Can we do this using uipath ? is there any dependent package to resolve this issue?

yes invoke code activity can take C#

Cheers @prasanna.Ui

Hi @prasanna.Ui

In the invoke code activity you can select the language


Hi @prasanna.Ui ,

You need to import namespace ‘System.ServiceProcesses’ before invoking code.
Temp.xaml (6.8 KB)

Hope this helps.

1 Like

still you dont use classes, methods or functions in there…

Hi Lipika,

Thanks .

I have tried in the same but I getting below error could you please help me to resolve this.
getting below error.

Hi @prasanna.Ui,

Check this prerequisites before execution or starting service through code

  1. The service should be present in services.
  2. Right click on the services and from properties fetch the service Name-
  3. In Invoke code-

Hi, I am using UIPath 2020.10.2 Pro and experimenting with InvokeCode. To me it seems that invoking code of C# is only possible in c# projects types and VB InvokeCode is only possible in VB project types.

In other words, is it possible to have both languages with “InvokeCode” mixed in one project?

Unfortunately neither in Studio itself or in the doc pages cited above this constraint is documented, so I am curious.
WIW, in my VB project I am getting an error invoking C# code even for the simplest line, so I assume, it is not possible.

But maybe it is possible to workaround this adding appropriate namespaces to the .xaml ?