# Invoke c# code compilation error

**URL:** <https://discourse.openiap.io/t/invoke-c-code-compilation-error/645>\
**Category:** OpenRPA\
**Created:** [July 3, 2023, 8:12pm UTC](https://discourse.openiap.io/t/invoke-c-code-compilation-error/645 "2023-07-03T20:12:46Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![BACCMED](https://discourse.openiap.io/letter_avatar_proxy/v4/letter/b/a8b319/32.png) [@BACCMED](https://discourse.openiap.io/u/BACCMED)\
**Post date:** [July 3, 2023, 8:12pm UTC](https://discourse.openiap.io/t/invoke-c-code-compilation-error/645/1 "2023-07-03T20:12:46Z")

</div>

Hi @kowts ,

i tried to call a rest api with invoke code in C# ,

it’s a free api for test :

> **[Text Analysis API Documentation (gaurmanojkumar530) | RapidAPI](https://rapidapi.com/gaurmanojkumar530/api/text-analysis12)**
>
> sentiment-analysis, text-summarization, language-detection, article-extraction, named-entity-recognition, extract-text from documents and images

 ![image](https://discourse.openiap.io/uploads/default/original/1X/c696e60baf7b8dc8b20f1504faab2e376a0e014f.png)

I copied the code and insert them in invoke code activity ,

 ![image](https://discourse.openiap.io/uploads/default/original/1X/c8a333d070914243be7e2ca4383a30729dd3a54f.png)

it give this error  
error CS1003: Erreur de syntaxe, ‘(’ attenduc:\Users\DELL\AppData\Local\Temp\mxqntruf.0.cs(22,30) : error CS1026: ) attendue

the copied code :  
using System.Net.Http.Headers;  
var client = new HttpClient();  
var request = new HttpRequestMessage  
{  
Method = HttpMethod.Post,  
RequestUri = new Uri(“[https://text-analysis12.p.rapidapi.com/text-mining/api/v1.1](https://text-analysis12.p.rapidapi.com/text-mining/api/v1.1)”),  
Headers =  
{  
{ “X-RapidAPI-Key”, “c46259ecc6msh68576a8d2542dadp1205c9jsnb9ae8c2612af” },  
{ “X-RapidAPI-Host”, “[text-analysis12.p.rapidapi.com](http://text-analysis12.p.rapidapi.com)” },  
},  
Content = new MultipartFormDataContent  
{  
new StringContent(“”)  
{  
Headers =  
{  
ContentType = new MediaTypeHeaderValue(“application/octet-stream”),  
ContentDisposition = new ContentDispositionHeaderValue(“form-data”)  
{  
Name = “input\_file”,  
FileName = “test.txt”,  
}  
}  
},  
new StringContent(“english”)  
{  
Headers =  
{  
ContentDisposition = new ContentDispositionHeaderValue(“form-data”)  
{  
Name = “language”,  
}  
}  
},  
},  
};  
using (var response = await client.SendAsync(request))  
{  
response.EnsureSuccessStatusCode();  
var body = await response.Content.ReadAsStringAsync();  
Console.WriteLine(body);  
}

---

<div class="post-metadata">

**Author:** ![Allan\_Zimmermann](https://discourse.openiap.io/user_avatar/discourse.openiap.io/allan_zimmermann/32/12_2.png) [@Allan\_Zimmermann](https://discourse.openiap.io/u/Allan_Zimmermann)\
**Post date:** [July 4, 2023, 6:59am UTC](https://discourse.openiap.io/t/invoke-c-code-compilation-error/645/2 "2023-07-04T06:59:24Z")

</div>

Invoke code is wrapping a function. you cannot use “import” inside a fuction.

If you type `Console.Writeline("Hi mom")` inside Invoke code it will generated someting like

```csharp
using first.import.from.importstab;
using second.import.from.importstab;
namespace SomeNamespace { public class {
    public static variable1type variable1 = default(variable1type);
    public static variable2type variable2 = default(variable2type);
    public static void ExpressionValue() { 
       Console.Writeline("Hi mom")
    }
}}

```

It compiles this to a type and calls ExpressionValue()  
This is why you get debug messages in the console, to let you know the number of lines added to the type, so when you get an error message you know how many lines to subtract from the line number in the error message to find it in your invoke code code editor

---

<div class="post-metadata">

**Author:** ![BACCMED](https://discourse.openiap.io/letter_avatar_proxy/v4/letter/b/a8b319/32.png) [@BACCMED](https://discourse.openiap.io/u/BACCMED)\
**Post date:** [July 4, 2023, 7:56am UTC](https://discourse.openiap.io/t/invoke-c-code-compilation-error/645/3 "2023-07-04T07:56:39Z")

</div>

Thank you for reply ,

What is the suggestion in this case ,  
Do you have an example of C# invoke code running OR is there another solution ?  
Your help is much appreciated.

---

<div class="post-metadata">

**Author:** ![Allan\_Zimmermann](https://discourse.openiap.io/user_avatar/discourse.openiap.io/allan_zimmermann/32/12_2.png) [@Allan\_Zimmermann](https://discourse.openiap.io/u/Allan_Zimmermann)\
**Post date:** [July 4, 2023, 8:09am UTC](https://discourse.openiap.io/t/invoke-c-code-compilation-error/645/4 "2023-07-04T08:09:42Z")

</div>

As i wrote, remove the using System.Net.Http.Headers;  
and add the fqdn in the code instead ( or add System.Net.Http.Headers in the imports tab )

---

<div class="post-metadata">

**Author:** ![BACCMED](https://discourse.openiap.io/letter_avatar_proxy/v4/letter/b/a8b319/32.png) [@BACCMED](https://discourse.openiap.io/u/BACCMED)\
**Post date:** [July 4, 2023, 9:18am UTC](https://discourse.openiap.io/t/invoke-c-code-compilation-error/645/5 "2023-07-04T09:18:50Z")

</div>

I added System.Net.Http.Headers in the imports tab ,

 ![image](https://discourse.openiap.io/uploads/default/original/1X/554bea91b69d9d16c638a5fc8d715c8c59a2976b.png)

But i have this error

 ![image](https://discourse.openiap.io/uploads/default/original/1X/28e45fda8dfb5ab54548ece9b06e940de1d6e1e0.png)

---

<div class="post-metadata">

**Author:** ![BACCMED](https://discourse.openiap.io/letter_avatar_proxy/v4/letter/b/a8b319/32.png) [@BACCMED](https://discourse.openiap.io/u/BACCMED)\
**Post date:** [July 4, 2023, 9:24am UTC](https://discourse.openiap.io/t/invoke-c-code-compilation-error/645/6 "2023-07-04T09:24:56Z")

</div>

Is there an example of invoke code running with C# calling a rest api ?  
it will be very helpful for us.

---

<div class="post-metadata">

**Author:** ![Allan\_Zimmermann](https://discourse.openiap.io/user_avatar/discourse.openiap.io/allan_zimmermann/32/12_2.png) [@Allan\_Zimmermann](https://discourse.openiap.io/u/Allan_Zimmermann)\
**Post date:** [July 4, 2023, 9:45am UTC](https://discourse.openiap.io/t/invoke-c-code-compilation-error/645/7 "2023-07-04T09:45:12Z")

</div>

```csharp
var client = new System.Net.Http.HttpClient();
var request = new System.Net.Http.HttpRequestMessage
{
    Method = System.Net.Http.HttpMethod.Post,
    RequestUri = new Uri("https://text-analysis12.p.rapidapi.com/language-detection/api/v1.1"),
    Headers = {
        { "X-RapidAPI-Key", "SIGN-UP-FOR-KEY" },
        { "X-RapidAPI-Host", "text-analysis12.p.rapidapi.com" },
    },
    Content = new System.Net.Http.StringContent("{ \"text\": \"Hello how are you? Have you heard about SpaceX?\"}")
    {
        Headers = { ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json") }
    }
};

var responseTask = client.SendAsync(request);
responseTask.Wait();
var response = responseTask.Result;
response.EnsureSuccessStatusCode();

var bodyTask = response.Content.ReadAsStringAsync();
bodyTask.Wait();
var body = bodyTask.Result;
Console.WriteLine(body);

```

---

<div class="post-metadata">

**Author:** ![BACCMED](https://discourse.openiap.io/letter_avatar_proxy/v4/letter/b/a8b319/32.png) [@BACCMED](https://discourse.openiap.io/u/BACCMED)\
**Post date:** [July 4, 2023, 10:26am UTC](https://discourse.openiap.io/t/invoke-c-code-compilation-error/645/8 "2023-07-04T10:26:01Z")

</div>

Thank you ,

it compile.

---

<div class="post-metadata">

**Author:** ![system](https://discourse.openiap.io/uploads/default/original/2X/a/a1ca7b164ac9a826839704d9ac82c7b5e6bcf557.png) [@system](https://discourse.openiap.io/u/system)\
**Post date:** [July 7, 2023, 10:26am UTC](https://discourse.openiap.io/t/invoke-c-code-compilation-error/645/9 "2023-07-07T10:26:51Z")

</div>

Closed on July 7, 2023, 10:26am UTC

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
