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

自作多情 提交于 2021-02-08 19:52:07

问题


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

回答1:


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
}


来源:https://stackoverflow.com/questions/49838359/c-sharp-aws-sqs-client-inaccessible-due-to-its-protection-level

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!