Unity3D 中调用 AWS ListBuckets 的 ObjectDisposedException
ObjectDisposedException on AWS ListBuckets call in Unity3D
我正在尝试在 Unity3D 游戏中使用 AWS .NET SDK。我已经采用了 3.5 dll,并且在我的项目中使用了它。为了测试它是否正常工作,我只是试图列出所有可用的存储桶,我已经使用 Cloudberry 检查了所有凭据和权限是否正确,所以这应该不是问题。
抛出异常:
ObjectDisposedException: The object was used after being disposed.
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:Update()
单步执行代码后,错误似乎出现在 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);
}
}
}
我已经取出这个 class 并将其放入 运行 .NET 3.5 的 visual studio 项目中进行测试,它运行良好并列出了所有我期望的水桶。
这个错误感觉没什么用,所以我不确定这是库和 Unity 的问题还是我的代码有问题。可能是什么原因造成的,或者有人知道解决方案吗?
想要完全相同的东西和 运行 遇到同样的问题。
这并不完美,但解决方法如下:
结帐https://github.com/aws/aws-sdk-net
你必须打补丁
Amazon.Runtime.Internal.Unmarshaller
private void Unmarshall(IExecutionContext executionContext)
HttpsResponse 被放置在 finally 块中。如果您只是对此发表评论,那么您又回来了。
我认为这是旧的单声道运行时的问题,但我也不明白为什么这会奏效。但是因为我只希望它能工作... :-) GC 也会清理响应对象,所以你甚至不会遇到麻烦。
顺便说一句:这实际上 真的 很容易做到。只需签出该项目。打开3.5版本。 Build 立即为我工作。所以这大约需要 10 分钟。
我正在尝试在 Unity3D 游戏中使用 AWS .NET SDK。我已经采用了 3.5 dll,并且在我的项目中使用了它。为了测试它是否正常工作,我只是试图列出所有可用的存储桶,我已经使用 Cloudberry 检查了所有凭据和权限是否正确,所以这应该不是问题。
抛出异常:
ObjectDisposedException: The object was used after being disposed. 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:Update()
单步执行代码后,错误似乎出现在 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);
}
}
}
我已经取出这个 class 并将其放入 运行 .NET 3.5 的 visual studio 项目中进行测试,它运行良好并列出了所有我期望的水桶。
这个错误感觉没什么用,所以我不确定这是库和 Unity 的问题还是我的代码有问题。可能是什么原因造成的,或者有人知道解决方案吗?
想要完全相同的东西和 运行 遇到同样的问题。
这并不完美,但解决方法如下:
结帐https://github.com/aws/aws-sdk-net
你必须打补丁
Amazon.Runtime.Internal.Unmarshaller
private void Unmarshall(IExecutionContext executionContext)
HttpsResponse 被放置在 finally 块中。如果您只是对此发表评论,那么您又回来了。
我认为这是旧的单声道运行时的问题,但我也不明白为什么这会奏效。但是因为我只希望它能工作... :-) GC 也会清理响应对象,所以你甚至不会遇到麻烦。
顺便说一句:这实际上 真的 很容易做到。只需签出该项目。打开3.5版本。 Build 立即为我工作。所以这大约需要 10 分钟。