# Csharp invoke code error

**URL:** <https://forum.uipath.com/t/csharp-invoke-code-error/296055>\
**Category:** Activities\
**Tags:** question, system, activities\
**Created:** [March 5, 2021, 2:55pm UTC](https://forum.uipath.com/t/csharp-invoke-code-error/296055 "2021-03-05T14:55:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kishore.shetty1](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/kishore.shetty1/32/177051_2.png) [@kishore.shetty1](https://forum.uipath.com/u/kishore.shetty1)\
**Post date:** [March 5, 2021, 2:55pm UTC](https://forum.uipath.com/t/csharp-invoke-code-error/296055/1 "2021-03-05T14:55:01Z")

</div>

Hi everyone,

I’m trying to execute csharp code using invoke activity but it throws this error

 ![image](https://global.discourse-cdn.com/uipath/original/3X/6/f/6f5831d6ccfac529945543ecb48891fa05244af5.png)

the code im using

class Program  
{  
static void Main(string args)  
{  
Method1();  
Method2();  
Console.ReadKey();  
}  
public static async Task Method1()  
{  
await Task.Run(() =\>  
{  
for (int i = 0; i \< 100; i++)  
{  
// Do something  
Task.Delay(100).Wait();  
}  
});  
}  
public static void Method2()  
{  
for (int i = 0; i \< 25; i++)  
{  
// Do something  
Task.Delay(100).Wait();  
}  
System.Environment.Exit(0);  
}  
}

Please can anyone tell me what is this error because its running fine in VS

---

<div class="post-metadata">

**Author:** ![Yoichi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/yoichi/32/523754_2.png) [@Yoichi](https://forum.uipath.com/u/Yoichi)\
**Post date:** [March 7, 2021, 8:06am UTC](https://forum.uipath.com/t/csharp-invoke-code-error/296055/2 "2021-03-07T08:06:36Z")

</div>

Hi,

In Invoke Code activity, we need to write code like content of a method.  
The following sample might helps you.

> **[Invoke Code](https://docs.uipath.com/activities/docs/invoke-code)**
>
> UiPath.Core.Activities.InvokeCode Synchronously invokes VB.NET or C# code, optionally passing it a list of input arguments. This activity can also return out arguments to the caller workflow. Properties Input Arguments - The parameters that can be...

Regards,
