# Can't upload attachment to task using C#, receiving "file: File is not an object"

**URL:** <https://forum.asana.com/t/cant-upload-attachment-to-task-using-c-receiving-file-file-is-not-an-object/106913>\
**Category:** API & Developers\
**Created:** [19 January 2021 21:24 UTC](https://forum.asana.com/t/cant-upload-attachment-to-task-using-c-receiving-file-file-is-not-an-object/106913 "2021-01-19T21:24:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_Forden](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/eric_forden/32/24509_2.png) [@Eric\_Forden](https://forum.asana.com/u/Eric_Forden)\
**Post date:** [19 January 2021 21:24 UTC](https://forum.asana.com/t/cant-upload-attachment-to-task-using-c-receiving-file-file-is-not-an-object/106913/1 "2021-01-19T21:24:52Z")

</div>

Hello,

I’m using a C# .NET Core MVC web app to create/update tasks. One last feature I’m building out is to attach a file to a task.

Here is my C# code:

```auto
using var client = new HttpClient();

client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {_token}");

var uri = _configuration.GetValue<string>("Asana:TaskUri");
uri += string.Format("/{0}/attachments", task.TaskGid);

byte[] bytes = await System.IO.File.ReadAllBytesAsync(fileName);

var content = new MultipartFormDataContent(Guid.NewGuid().ToString())
{
{ new ByteArrayContent(bytes), "\"file\"" }
};

var response = await client.PostAsync(uri, content);

var responseString = await response.Content.ReadAsStringAsync();

```

Executing the above code and passing a PDF file always results in a “file: File is not an object” error, and I can’t seem to figure out why.

Here is the JSON response:

```auto
{"errors":[{"message":"file: File is not an object","help":"For more information on API status codes and how to handle them, read the docs on errors: https://developers.asana.com/docs/errors"}]}

```

Does anyone have any suggestions what I’m doing wrong?

Thank you!

---

<div class="post-metadata">

**Author:** ![Frederic\_Malenfant](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/frederic_malenfant/32/8358_2.png) [@Frederic\_Malenfant](https://forum.asana.com/u/Frederic_Malenfant)\
**Post date:** [20 January 2021 22:00 UTC](https://forum.asana.com/t/cant-upload-attachment-to-task-using-c-receiving-file-file-is-not-an-object/106913/2 "2021-01-20T22:00:26Z")

</div>

Ok, it’s VB not C# but it’s the same framework you’ll understand.  
Oh you’re using “core”, I think webclient is also available.

Dim wc As New Net.WebClient  
wc.Headers.Add("Authorization: Bearer " & token)  
url = “[https://app.asana.com/api/1.0/tasks/](https://app.asana.com/api/1.0/tasks/)” & idTask & “/attachments”  
resp = wc.UploadFile(url, fileName)  
wc.Dispose()

---

<div class="post-metadata">

**Author:** ![Eric\_Forden](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/eric_forden/32/24509_2.png) [@Eric\_Forden](https://forum.asana.com/u/Eric_Forden)\
**Post date:** [21 January 2021 14:51 UTC](https://forum.asana.com/t/cant-upload-attachment-to-task-using-c-receiving-file-file-is-not-an-object/106913/3 "2021-01-21T14:51:26Z")

</div>

I ended up using RestSharp and it worked right away…

```
var request = new RestRequest(Method.POST);
request.AddFile("file", filePath);
IRestResponse response = await client.ExecuteAsync(request);

```

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/system/32/276370_2.png) [@system](https://forum.asana.com/u/system)\
**Post date:** [30 May 2025 19:06 UTC](https://forum.asana.com/t/cant-upload-attachment-to-task-using-c-receiving-file-file-is-not-an-object/106913/4 "2025-05-30T19:06:08Z")

</div>

Closed on 30 May 2025 19:06 UTC


