结果委托从未在 Unity3D (C#) 的 DynamoDB 中调用 Load table
Result Delegate never called to Load table in DynamoDB in Unity3D (C#)
- 统一版本:2017.3.1f1
- AWS 服务:DynamoDB
- 测试环境:编辑器MacOSX
场景
正在尝试从 Dynamo DB 加载 table 但遇到奇怪的问题。
当我使用有效的主 HASH 键时加载非常好,但当我提供错误的 HASH 键(数据库中不存在的键)时,永远不会调用委托。
来源
private void performLoadOperation()
{
ExperienceListing _experienceListing = null;
string _ISEN = "21-89297083-ebe3-40b2-a269-3cfe80922fed";
DH.log ("About to load ");
Context.LoadAsync<ExperienceListing>
(_ISEN, (_result)=>
{
Debug.Log ("result returned - " + _result.Result.Title);
if(_result.Exception == null)
{
_experienceListing = _result.Result as ExperienceListing;
Debug.Log ("Title - " + _result.Result.Title);
}
else
{
Debug.Log ("Exception - " + _result.Exception);
}
}
);
}
[DynamoDBTable("ExperienceListing")]
public class ExperienceListing
{
[DynamoDBHashKey] // Hash key.
public string ISEN{ get; set; }
[DynamoDBProperty]
public string Title{ get; set; }
[DynamoDBProperty]
public string Blurb{get;set;}
[DynamoDBProperty]
public int Views{ get; set; }
[DynamoDBProperty]
public int Rating{ get; set; }
}
测试用例
对于上面的performLoadOperation(),delegate被正确调用了。现在假设我将 _ISEN 变量更改为数据库中不存在的字符串,委托永远不会被调用。我想指出的是,互联网是可用的。
请求
- 我是否应该始终提供正确的散列键,并且应该明白永远不会为 invalid/wrong 散列键调用委托?
编辑
以下对我有用,但仍然很奇怪。
private void performLoadOperation()
{
ExperienceListing _experienceListing = null;
string _ISEN = "08c0ba69-af71-4017-afb8-5040f7033b33";
DH.log ("About to load ");
Context.LoadAsync<ExperienceListing>
(_ISEN, (_result)=>
{
if(_result.Exception == null)
{
_experienceListing = _result.Result as ExperienceListing;
Debug.Log ("No Exception");
if(_experienceListing == null)
{
Debug.Log ("Experience Listing is null");
}
else
{
Debug.Log ("Experience Listing not null - " + _experienceListing.Title);
}
}
else
{
Debug.Log ("Exception - " + _result.Exception.Message);
}
if(_result == null)
{
Debug.Log ("Return result is null");
}
}, null
);
}
当“_result”的none访问打印日志时,打印日志。根据@MikeDinescu 的建议,使用断点进行测试,表明调用了委托。
使用上述解决方案,当_result 仍然不为null 时- 需要手动检查_experienceListing 以了解DyanomoDB 是否有来自hash key 的任何table。
无论操作是否检索到结果,都应调用委托。如果没有与键匹配的项目,Result
将为 null 并且 Exception 将包含错误详细信息。
但是,回调 lambda 在第一行包含空引用异常。很可能发生的情况是 lambda 被调用但立即抛出异常,因为它试图取消引用 Null 结果。
确定没有调用?您是否尝试过在 lambda 的第一行放置一个断点?
要尝试的另一件事是将回调 lambda 中的第一个 Debug.WriteLine
更改为一个简单的字符串,删除试图取消引用 _result.Result
的部分,然后检查调试是否正确即使结果是异常,也会打印消息。
- 统一版本:2017.3.1f1
- AWS 服务:DynamoDB
- 测试环境:编辑器MacOSX
场景
正在尝试从 Dynamo DB 加载 table 但遇到奇怪的问题。
当我使用有效的主 HASH 键时加载非常好,但当我提供错误的 HASH 键(数据库中不存在的键)时,永远不会调用委托。
来源
private void performLoadOperation()
{
ExperienceListing _experienceListing = null;
string _ISEN = "21-89297083-ebe3-40b2-a269-3cfe80922fed";
DH.log ("About to load ");
Context.LoadAsync<ExperienceListing>
(_ISEN, (_result)=>
{
Debug.Log ("result returned - " + _result.Result.Title);
if(_result.Exception == null)
{
_experienceListing = _result.Result as ExperienceListing;
Debug.Log ("Title - " + _result.Result.Title);
}
else
{
Debug.Log ("Exception - " + _result.Exception);
}
}
);
}
[DynamoDBTable("ExperienceListing")]
public class ExperienceListing
{
[DynamoDBHashKey] // Hash key.
public string ISEN{ get; set; }
[DynamoDBProperty]
public string Title{ get; set; }
[DynamoDBProperty]
public string Blurb{get;set;}
[DynamoDBProperty]
public int Views{ get; set; }
[DynamoDBProperty]
public int Rating{ get; set; }
}
测试用例
对于上面的performLoadOperation(),delegate被正确调用了。现在假设我将 _ISEN 变量更改为数据库中不存在的字符串,委托永远不会被调用。我想指出的是,互联网是可用的。
请求
- 我是否应该始终提供正确的散列键,并且应该明白永远不会为 invalid/wrong 散列键调用委托?
编辑
以下对我有用,但仍然很奇怪。
private void performLoadOperation()
{
ExperienceListing _experienceListing = null;
string _ISEN = "08c0ba69-af71-4017-afb8-5040f7033b33";
DH.log ("About to load ");
Context.LoadAsync<ExperienceListing>
(_ISEN, (_result)=>
{
if(_result.Exception == null)
{
_experienceListing = _result.Result as ExperienceListing;
Debug.Log ("No Exception");
if(_experienceListing == null)
{
Debug.Log ("Experience Listing is null");
}
else
{
Debug.Log ("Experience Listing not null - " + _experienceListing.Title);
}
}
else
{
Debug.Log ("Exception - " + _result.Exception.Message);
}
if(_result == null)
{
Debug.Log ("Return result is null");
}
}, null
);
}
当“_result”的none访问打印日志时,打印日志。根据@MikeDinescu 的建议,使用断点进行测试,表明调用了委托。
使用上述解决方案,当_result 仍然不为null 时- 需要手动检查_experienceListing 以了解DyanomoDB 是否有来自hash key 的任何table。
无论操作是否检索到结果,都应调用委托。如果没有与键匹配的项目,Result
将为 null 并且 Exception 将包含错误详细信息。
但是,回调 lambda 在第一行包含空引用异常。很可能发生的情况是 lambda 被调用但立即抛出异常,因为它试图取消引用 Null 结果。
确定没有调用?您是否尝试过在 lambda 的第一行放置一个断点?
要尝试的另一件事是将回调 lambda 中的第一个 Debug.WriteLine
更改为一个简单的字符串,删除试图取消引用 _result.Result
的部分,然后检查调试是否正确即使结果是异常,也会打印消息。