简体   繁体   中英

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.");
}

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM