尝试通过 AWS C# SDK (digitalocean) 获取对象列表时出现异常

Disposed exception when trying get objects list via AWS C# SDK (digitalocean)

为什么当我尝试获取对象列表(或例如存储桶列表)时出现处置异常?

System.ObjectDisposedException: "Cannot access a disposed object. ObjectDisposed_ObjectName_Name"

private string S3_ACCESS_KEY = "blablabla";
private string S3_SECRET_KEY = "blablabla";
private string S3_HOST_ENDPOINT = "https://fra1.digitaloceanspaces.com";
private string S3_BUCKET_NAME = "launchers";
private AmazonS3Client _client;

public DO()
{
    AmazonS3Config config = new AmazonS3Config();
    config.ServiceURL = S3_HOST_ENDPOINT;
    _client = new AmazonS3Client(S3_ACCESS_KEY, S3_SECRET_KEY, config);
}

public List<string> ListObject()
{
    var objects = _client.ListObjects(S3_BUCKET_NAME); // System.ObjectDisposedException: "Cannot access a disposed object.ObjectDisposed_ObjectName_Name"
    var objectsList = objects.S3Objects.Select(c => c.Key).ToList();
    return objectsList;
}       

我还是不明白是什么原因,但是我解决了问题。

  1. 删除了 awssdk 并安装了 awssdk.s3 (Nuget)
  2. 更改了代码
public List<S3Object> ListObject()
{
    var objects = _client.ListObjectsAsync(S3_BUCKET_NAME).Result;
    return objects.S3Objects.ToList();
}

现在可以了