TLDR:无法在QueryAsync或ScanAsync中创建AsyncSearch对象,而不会在AWS库深处陷入奇怪的ArgumentNullException。
我在Unity开发在线游戏,并希望与DynamoDB同步数据。当我只有一张包含球员数据的桌子时,这非常有效。我只想使用" DBContext.LoadAsync(id,callback);"它完美无瑕。使用" SaveAsync"保存同样有效。
现在我介绍了一些表,我需要执行扫描和查询。出于测试目的,我给了我的Unity应用程序它可能拥有的所有权利(我使用" dynamodb:*"和"资源":[" *" ]在IAM)。
我基本上尝试了所有可能的ScanAsync,QueryAsync和FromQueryAsync版本,但是我总是遇到错误。
简单示例:我想下载(我所在大学)的所有部门:
AsyncSearch<DepartmentData> search = AWSManager.Instance.DBContext.ScanAsync<DepartmentData>();
此调用已失败,之后我可以执行任何类似&#34; search.GetRemainingAsync(callback)&#34;的操作。对于简单的查询也是如此:
AsyncSearch<POIVisit> query = AWSManager.Instance.DBContext.QueryAsync<POIVisit>(poiType);
错误如下,并且位于AWS库的深处,因此我无法真正进入,设置一些断点并查看究竟是什么失败:
ArgumentNullException: Argument cannot be null.
Parameter name: key
System.Collections.Generic.Dictionary`2[System.Type,Amazon.Runtime.IExceptionHandler].TryGetValue (System.Type key, IExceptionHandler& value) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:588)
Amazon.Runtime.Internal.ErrorHandler.ProcessException (IExecutionContext executionContext, System.Exception exception) (at E:/JenkinsWorkspaces/v3-trebuchet-release/AWSDotNetPublic/sdk/src/Core/Amazon.Runtime/Pipeline/ErrorHandler/ErrorHandler.cs:202)
Amazon.Runtime.Internal.ErrorHandler.InvokeSync (IExecutionContext executionContext) (at E:/JenkinsWorkspaces/v3-trebuchet-release/AWSDotNetPublic/sdk/src/Core/Amazon.Runtime/Pipeline/ErrorHandler/ErrorHandler.cs:78)
Amazon.Runtime.Internal.PipelineHandler.InvokeSync (IExecutionContext executionContext) (at E:/JenkinsWorkspaces/v3-trebuchet-release/AWSDotNetPublic/sdk/src/Core/Amazon.Runtime/Pipeline/PipelineHandler.cs:57)
Amazon.Runtime.Internal.CallbackHandler.InvokeSync (IExecutionContext executionContext) (at E:/JenkinsWorkspaces/v3-trebuchet-release/AWSDotNetPublic/sdk/src/Core/Amazon.Runtime/Pipeline/Handlers/CallbackHandler.cs:45)
Amazon.Runtime.Internal.PipelineHandler.InvokeSync (IExecutionContext executionContext) (at E:/JenkinsWorkspaces/v3-trebuchet-release/AWSDotNetPublic/sdk/src/Core/Amazon.Runtime/Pipeline/PipelineHandler.cs:57)
Amazon.Runtime.Internal.Signer.InvokeSync (IExecutionContext executionContext) (at E:/JenkinsWorkspaces/v3-trebuchet-release/AWSDotNetPublic/sdk/src/Core/Amazon.Runtime/Pipeline/Handlers/Signer.cs:38)
Amazon.Runtime.Internal.PipelineHandler.InvokeSync (IExecutionContext executionContext) (at E:/JenkinsWorkspaces/v3-trebuchet-release/AWSDotNetPublic/sdk/src/Core/Amazon.Runtime/Pipeline/PipelineHandler.cs:57)
Amazon.Runtime.Internal.CredentialsRetriever.InvokeSync (IExecutionContext executionContext) (at E:/JenkinsWorkspaces/v3-trebuchet-release/AWSDotNetPublic/sdk/src/Core/Amazon.Runtime/Pipeline/Handlers/CredentialsRetriever.cs:72)
Amazon.Runtime.Internal.PipelineHandler.InvokeSync (IExecutionContext executionContext) (at E:/JenkinsWorkspaces/v3-trebuchet-release/AWSDotNetPublic/sdk/src/Core/Amazon.Runtime/Pipeline/PipelineHandler.cs:57)
Amazon.Runtime.Internal.RetryHandler.InvokeSync (IExecutionContext executionContext) (at E:/JenkinsWorkspaces/v3-trebuchet-release/AWSDotNetPublic/sdk/src/Core/Amazon.Runtime/Pipeline/RetryHandler/RetryHandler.cs:74)
如果我想基于二级索引进行查询,情况会变得更糟。为此,我需要在hash和range键的条件之后附加一个DynamoDBOperationConfig,如下所示:
var queryConfig = new DynamoDBOperationConfig() { IndexName = "PlayerIndex" };
AsyncSearch<POIVisit> query = AWSManager.Instance.DBContext.QueryAsync<POIVisit>(poiType, QueryOperator.Equal, PlayerID, queryConfig);
现在,它似乎在某种程度上认为,queryConfig只是范围键的另一个值(因此它基本上选择了错误的QueryAsync重载版本)。或者至少我认为会发生什么,因为我现在得到了一个奇怪的转换错误:
InvalidCastException: Cannot cast from source type to destination type.
Amazon.DynamoDBv2.Converter`1[T].TryTo (System.Object value, Amazon.DynamoDBv2.DocumentModel.Primitive& p) (at E:/JenkinsWorkspaces/v3-trebuchet-release/AWSDotNetPublic/sdk/src/Services/DynamoDBv2/Custom/Conversion/DynamoDBEntryConversion.cs:630)
…
Amazon.DynamoDBv2.DataModel.DynamoDBContext.QueryAsync[POIVisit] (System.Object hashKeyValue, QueryOperator op, System.Object[] values) (at E:/JenkinsWorkspaces/v3-trebuchet-release/AWSDotNetPublic/sdk/src/Services/DynamoDBv2/Custom/DataModel/_unity/Context.Async.cs:550)
DBManager.RetrievePlayerVisits (System.String poiType, UnityEngine.Events.UnityAction`1 callback) (at Assets/Scripts/Managers/DBManager.cs:359)
我的Unity版本是5.6.3f1。我尝试了AWSSDK.DynamoDBv2.3.3.4.18和包含直接从亚马逊下载的AWS SDK的旧版AWSSDK.DynamoDBv2.3.3.4.14 Unity软件包。
如果有人暗示我可能做错了什么,我真的很感激,谢谢!
答案 0 :(得分:0)
您需要在创建查询之前构建请求对象。我从来没有使用Unity,但它应该像
npm i
具体来说,您似乎没有将关键条件作为请求的一部分包含在内,这是必需的。