-3

I have an below C# Code,It works fine in Visual studio 2017 with .Net Framework 4.0,But when I run the same source code in visual studio 2010 with .net Framework then its not working and its shows an compiled error message near async and wait .Please advise the alternate solution to do this.

Source Code :-

static string url = "https://einvoicing.internal.cleartax.co/v2/eInvoice/download?irns=7b46fb61d6e0883bdfdfb997ca25c4b5629d3062241532f6e8e6fcdfc0a95c9a";
static HttpClient client = new HttpClient(); 
static async Task DownloadCurrentAsync(string StrInvoiceNo)
        {

            client.DefaultRequestHeaders.Add("owner_id", "78c6beda-54a2-11ea-b064-0af3f8b02c24");
            client.DefaultRequestHeaders.Add("gstin", "29AAFCD5862R000");
            HttpResponseMessage response = await client.GetAsync(url);
            
            response.EnsureSuccessStatusCode(); // <= Will throw if unsuccessful
            using (FileStream fileStream = new FileStream(StrInvoiceNo.Replace("/","-") + ".pdf", FileMode.Create, FileAccess.Write, FileShare.None))
            {
                //copy the content from response to filestream
                await response.Content.CopyToAsync(fileStream);
                System.Diagnostics.Process.Start(StrInvoiceNo.Replace("/", "-") + ".pdf");
            }
        }
Materials
  • 7
  • 6

1 Answers1

2

async and await have been introduced in C# 5. Visual Studio 2010 supports C# 4. Thats why you can't compile code with async/await under VS 2010.

Lukasz Szczygielek
  • 2,768
  • 2
  • 20
  • 34