Invoke Code C# - Error

Hi, I picked an API script in C# from Postam and tried using it in UiPath via the Invoke Code Activity.
I have instaled the Restsharp as a dependency in project

image

When I hoover on the code everything seems ok,

image

However, I get the error message bellow. It shows that there is no timeout activity for ‘RestClient’, I found it when I hooverd on my mouse.

It appears I am missing something here. This is the error message I get

[Error] Invoke code: No compiled code to run
error CS1061: ‘RestClient’ does not contain a definition for ‘Timeout’ and no accessible extension method ‘Timeout’ accepting a first argument of type ‘RestClient’ could be found (are you missing a using directive or an assembly reference?) At line 2
error CS0117: ‘Method’ does not contain a definition for ‘POST’ At line 3
error CS0246: The type or namespace name ‘IRestResponse’ could not be found (are you missing a using directive or an assembly reference?) At line 16
error CS1061: ‘RestClient’ does not contain a definition for ‘Execute’ and no accessible extension method ‘Execute’ accepting a first argument of type ‘RestClient’ could be found (are you missing a using directive or an assembly reference?) At line 16
12/31/2021 10:59:02 => [Info] InvokeCodeTemplate execution ended in: 00:00:04
12/31/2021 10:59:02 => [Error] RemoteException wrapping System.ArgumentException: No compiled code to run
error CS1061: ‘RestClient’ does not contain a definition for ‘Timeout’ and no accessible extension method ‘Timeout’ accepting a first argument of type ‘RestClient’ could be found (are you missing a using directive or an assembly reference?) At line 2
error CS0117: ‘Method’ does not contain a definition for ‘POST’ At line 3
error CS0246: The type or namespace name ‘IRestResponse’ could not be found (are you missing a using directive or an assembly reference?) At line 16
error CS1061: ‘RestClient’ does not contain a definition for ‘Execute’ and no accessible extension method ‘Execute’ accepting a first argument of type ‘RestClient’ could be found (are you missing a using directive or an assembly reference?) At line 16

at UiPath.Activities.System.Utilities.InvokeCode.RoslynCompilerRunner.Compile(String code, Int32 errLineOffset, Boolean generateInMemory)
at UiPath.Activities.System.Utilities.InvokeCode.CSharpInvoker.GetCompilerRunner(String code, String className, String methodName, Int32 errLineOffset, Boolean inMemory)
at UiPath.Activities.System.Utilities.InvokeCode.NetCodeInvoker.GetCompilerRunner(String userCode, List1 args, String imps, Boolean inMemory) at UiPath.Activities.System.Utilities.InvokeCode.NetCodeInvoker.Run(String userCode, List1 inArgs, IEnumerable`1 imps, Object args)
at UiPath.Core.Activities.InvokeCode.Execute(CodeActivityContext context)
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.ActivityInstance.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location

@William_Blech_Sister

Hello William,
I tried it on the same way as you with Studio 21.4.1. …

image

image

… with this tiny code experiment …

image

… and all works well. No errors at compile time or runtime.

Which Studio version do you use?

Best regards
Stefan

Hi @StefanSchnell ,

I skipped the preview version for the RestSharp and it managed to run the C# Script.

Know I can ask the question I was looking for. I tried running the script and for some reason the C# is truncating the response.Content. This is some piece of evidence of that.

image

I was doing some experiences with C# in Visual Studio and discovered that string limitation was happening in .Net Framework 4.6.1 but not in .Net Core 3.1

Dear @Pablito @loginerror: UiPath currently runns (I am using 2021.10.4) on .Net Framework 4.6.1. Is it possible to change the target Framework? Is there a time table for that?

Regards

Hi @William_Blech_Sister,
We are moving our activities to the .Net Core and this might take some time. But what comes with it is the fact that all activities need to be reshaped and their background code is different. So in fact moving a project to the .Net Core might require a re-design of a project.

1 Like