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);
service.Start();
}
}

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?

Hi
yes invoke code activity can take C#

Cheers @prasanna.Ui

Hi @prasanna.Ui

In the invoke code activity you can select the language
Properties1

Thanks
Anoop

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.
Capture
getting below error.
Capture1

Hi @prasanna.Ui,

Check this prerequisites before execution or starting service through code

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

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 ?