Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# AWS SQS Client inaccessible due to it's protection level

So I've been having an issue getting the example from AWS to work for C#. I copy the code below straight from their site and put it in my program, but when it calls client.ListQueues(request); it tells me that it's inaccessible due to it's protection level. I've spent time searching, but I can't figure out why this isn't work. Any help would be appreciated.

var client = new AmazonSQSClient();

// List all queues that start with "aws".
var request = new ListQueuesRequest
{
  QueueNamePrefix = "aws"
};

var response = client.ListQueues(request);
var urls = response.QueueUrls;

if (urls.Any())
{
  Console.WriteLine("Queue URLs:");

  foreach (var url in urls)
  {
    Console.WriteLine("  " + url);
  }
}
else
{
  Console.WriteLine("No queues.");
}
like image 960
rammaidy Avatar asked Jan 03 '23 13:01

rammaidy


1 Answers

As it can be found in docs for some platforms the method ListQueues is not available. The docs says:

For .NET Core, PCL and Unity this operation is only available in asynchronous form. Please refer to ListQueuesAsync.

So you have to use the asynchronous method ListQueuesAsync and make your calling method asnyc. Your code should look like:

public async Task<Result> SomeAction()
{
    var client = new AmazonSQSClient();

    // List all queues that start with "aws".
    var request = new ListQueuesRequest
    {
        QueueNamePrefix = "aws"
    };

    var response = await client.ListQueuesAsync(request);

    // rest of the code
}
like image 111
arekzyla Avatar answered Jan 05 '23 15:01

arekzyla