azure-cosmosdb - CosmosDB C# Gremlin - 发送查询时出现异常
问题描述
取自:https ://docs.microsoft.com/en-us/azure/cosmos-db/create-graph-dotnet
在 .wait() 部分出现异常:
NullReferenceException: Object reference not set to an instance of an object.
at Gremlin.Net.Driver.Connection.ReceiveAsync[T]()
at Gremlin.Net.Driver.Connection.SubmitAsync[T](RequestMessage requestMessage)
at Gremlin.Net.Driver.ProxyConnection.SubmitAsync[T](RequestMessage requestMessage)
at Gremlin.Net.Driver.GremlinClient.SubmitAsync[T](RequestMessage requestMessage)
at Gremlin.Net.Driver.GremlinClientExtensions.SubmitAsync[T](IGremlinClient gremlinClient, String requestScript, Dictionary`2 bindings)
代码:
private static string database = "db";
private static string collection = "col";
private static string hostname = "grem-test.gremlin.cosmosdb.azure.com";
public void test()
{
var gremlinServer = new GremlinServer(hostname, 443, enableSsl: true,
username: "/dbs/" + database + "/colls/" + collection,
password: authKey);
var gremlinClient = new GremlinClient(gremlinServer);
var grem = "g.V()";
var t = gremlinClient.SubmitAsync<dynamic>(grem);
t.Wait();
foreach (var result in t.Result)
{
// The vertex results are formed as dictionaries with a nested dictionary for their properties
string output = JsonConvert.SerializeObject(result);
Console.WriteLine(String.Format("\tResult:\n\t{0}", output));
}
解决方案
它应该是:
var task = gremlinClient.SubmitAsync<dynamic>(grem);
task.Wait();
取自 Gremlin C# 示例:
// Create async task to execute the Gremlin query.
var task = gremlinClient.SubmitAsync<dynamic>(query.Value);
task.Wait();
推荐阅读
- mongodb - MongoDB:如何在集合中查找和替换 ObjectId
- r - 如何使用线性规划获得两个变量的最佳截止值
- css - div 不会随 CSS 属性改变大小
- robotframework - ROBOT Framework 无法点击弹出的接受按钮
- reactjs - 如何在加载 API 数据之前添加微调器?
- neural-network - 遗传算法 - 适应度函数
- python - 如何自动化将云监视图添加到仪表板的过程?
- c# - 当客户端超时取消控制器操作时,ASP.NET MVC3 应用程序将如何调用某些代码?
- java - Java.lang.OutOfMemoryError:将 xlsx 转换为 csv 格式时的 JAVA HEAP SPACE。我试过这个没有运气
-Xms400m -Xmx4096m - gatsby - Gatsby Algolia 基于标签的搜索