Unity3D中的AWS ListBuckets调用上的ObjectDisposedException

时间:2015-06-10 11:48:49

标签: amazon-web-services unity3d amazon-s3

我试图在Unity3D游戏中使用AWS .NET SDK。我已经使用了3.5 dll,我在我的项目中使用了它。为了测试它是否正常工作我只是尝试列出所有可用的存储桶,我已经使用Cloudberry检查了所有凭据和权限都是正确的,因此不应该是问题

抛出异常:

  

ObjectDisposedException:对象在被处置后使用。   System.Net.HttpWebResponse.CheckDisposed()   System.Net.HttpWebResponse.GetResponseHeader(System.String headerName)   (wrapper remoting-invoke-with-check)System.Net.HttpWebResponse:GetResponseHeader(string)   Amazon.Runtime.Internal.Transform.HttpWebRequestResponseData.GetHeaderValue(System.String name)   Amazon.S3.Internal.AmazonS3ResponseHandler.HasSSEHeaders(IWebResponseData webResponseData)   Amazon.S3.Internal.AmazonS3ResponseHandler.ProcessResponseHandlers(IExecutionContext executionContext)   Amazon.S3.Internal.AmazonS3ResponseHandler.PostInvoke(IExecutionContext executionContext)   Amazon.S3.Internal.AmazonS3ResponseHandler.InvokeSync(IExecutionContext executionContext)   Amazon.Runtime.Internal.PipelineHandler.InvokeSync(IExecutionContext executionContext)   Amazon.Runtime.Internal.ErrorHandler.InvokeSync(IExecutionContext executionContext)   UnityEngine.EventSystems.EventSystem:更新()

在单步执行代码后,错误似乎出现在显示var res = client.ListBuckets();的行上。这是正在使用的代码。

public class FileStorage
{
    private const string accessKey = @"access_key";
    private const string secretKey = @"secret_key";
    private const string bucketName = @"bucket_name";

    private AmazonS3Client client;
    private AmazonS3Config config;

    public FileStorage()
    {
        config = new AmazonS3Config
        {
            ServiceURL = "http://s3.amazonaws.com"
        };
    }

    public void ListBuckets()
    {
        var client = new AmazonS3Client(accessKey, secretKey, config);
        var res = client.ListBuckets();
        foreach (S3Bucket b in res.Buckets)
        {
            Debug.Log(b.BucketName);
        }
    }
}

我已经拿出这个课程并把它放到一个运行.NET 3.5的视觉工作室项目中进行测试,它运行得非常好并且列出了我所有的桶。期望的。

错误感觉相当无益,所以我不确定这是库和Unity的问题,还是我的代码出错了。可能导致这种情况的原因,或者是否有人知道解决方案?

1 个答案:

答案 0 :(得分:0)

想要完全相同的事情并遇到同样的问题。

这不是完美的,但这是解决方法:

结帐https://github.com/aws/aws-sdk-net

你必须修补

  Amazon.Runtime.Internal.Unmarshaller
      private void Unmarshall(IExecutionContext executionContext)

HttpsResponse被置于finally块中。如果您只是对此进行评论,那么您将重新开始营业。

我认为这对旧的单声道运行时有问题,但我也无法理解为什么这可能会起作用。但是因为我只想让它工作...... :-) GC也会清理响应对象,这样你甚至不会遇到麻烦。

BTW:这实际上真的很容易做到。检查项目。打开3.5版本。 Build立即为我工作。所以这将需要大约10分钟。