Neo4jClient System.NullReferenceException
Neo4jClient System.NullReferenceException
有时在 Neo4jClient 中我会收到此错误。我试图调查问题出在哪里,但我没有找到任何原因。有没有人有同样的问题或者可以帮助我?
谢谢
{"Message":"An error has occurred.","ExceptionMessage":"Object reference not set to an instance of an object.","ExceptionType":"System.NullReferenceException","StackTrace":" 在
Neo4jClient.GraphClient.Neo4jClient.IRawGraphClient.ExecuteGetCypherResults[TResult](CypherQuery 查询) in D:\temp17fa3\Neo4jClient.Shared\GraphClient.cs:line 919\r\n at
Mandarim.Storage.Neo4j.Manager.ManagerBase1.GetNodesRelatedOrderBy(String match, String id, String relationNodeType, String propertyOrderBy, Int32 skip, Int32 take, Direction direction,
Boolean distinct, Expression
1 其中)在 P:\Desenvolvimento\branchs\builder-3.0\Mandarim.Storage.Neo4j\Manager\ManagerBase.cs:line 2105\r\n在
Mandarim.Storage.Neo4j.Manager.ManagerBase1.GetNodesRelatedOrderBy(String id, Labels labelin, Labels labelout, String relationTypes, String propertyOrderBy, Int32 skip, Int32 take, Boolean
distinct, Expression
1 where, Direction direction) in P:\Desenvolvimento\branchs\builder-3.0\Mandarim.Storage.Neo4j\Manager\ManagerBase.cs:line 900\r\n 在
Mandarim.Factory.Base.FactoryBase1.GetNodesRelatedOrderBy(String id, Labels labelin, Labels labelout, String relationTypes, String propertyOrderBy, Int32 skip, Int32 take, Boolean distinct,
Expression
1 where, Direction direction) in P:\Desenvolvimento\branchs\builder-3.0\Mandarim.Factory\Base\FactoryBase.cs:line 177\r\n at
PackDocs.Services.Storage.MandarimStorageServices1.GetNodesRelatedOrderBy(String id, Labels labelin, Labels labelout, String propertyOrderBy, Int32 skip, Int32 take, Boolean distinct,
Expression
1 其中,Direction 方向,RelationTypes[] relationNodeType) in P:\Desenvolvimento\branchs\builder-3.0\Packdocs.Services.Storage\MandarimStorageServices.cs:line 292\r\n
在 Mandarim.PackDocs.Services.ManagerObjects.ManagerProject.GetProjects(Int32 skip, Int32 take, String orderby, CreatedState state) in
P:\Desenvolvimento\branchs\builder-3.0\PackDocs.Services\ManagerObjects\ManagerProject.cs:行 116\r\n 在 PackDocs.OWIN.Services.Host.Controllers.ProjectsController.GetProjects(Int32
skip, Int32 take, String orderby, CreatedState state) in P:\Desenvolvimento\branchs\builder-3.0\Packdocs.OWIN.Services.Host\Controllers\v2\ProjectsController.cs:line 103\r\n at
lambda_method(Closure , Object , Object[] )\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.b__9(Object instance, Object[]
methodParameters)\r\n 在 System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken
cancellationToken)\r\n--- 从先前抛出异常的位置开始的堆栈跟踪结束 ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)\r\n 在
System.Web.Http.Controllers.ApiControllerActionInvoker.d__0.MoveNext()\r\n--- 从先前抛出异常的位置开始的堆栈跟踪结束 ---\r\n at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)\r\n 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)\r\n 在
System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext()\r\n--- 从先前抛出异常的位置开始的堆栈跟踪结束 ---\r\n at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)\r\n 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)\r\n 在
System.Web.Http.Filters.AuthorizationFilterAttribute.d__2.MoveNext()\r\n--- 从先前抛出异常的位置开始的堆栈跟踪结束
---\r\n 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)\r\n 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务
任务)\r\n 在 System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()"}
更新
ContainerBuilder _builder = new ContainerBuilder();
_builder
.Register<ITransactionalGraphClient>(context =>
{
try
{
var neo4jUri = GetNeo4jSettingValue("neo4jUri");
var user = GetNeo4jSettingValue("neo4jUser");
var pwd = GetNeo4jSettingValue("neo4jPassword");
ITransactionalGraphClient graphClient = new GraphClient(new Uri(neo4jUri), user, pwd);
graphClient.Connect();
graphClient.JsonConverters.Add(new DictionaryConverter());
graphClient.JsonConverters.Add(new DateTimeConverter());
graphClient.JsonConverters.Add(new CommonDeserializerMethods());
return graphClient;
}
catch (Exception e)
{
Trace.TraceError(e.ToString());
throw e;
}
}).SingleInstance();
_container = _builder.Build();
获取实例
try
{
_myGraphClient = _myGraphClient ?? AutofacNeo4j.Container.Resolve<ITransactionalGraphClient>();
if (_myGraphClient != null && !_myGraphClient.IsConnected)
_myGraphClient.Connect();
return _myGraphClient;
}
catch (Exception e)
{
Trace.TraceError(e.ToString());
_myGraphClient = _myGraphClient ?? AutofacNeo4j.Container.Resolve<ITransactionalGraphClient>();
_myGraphClient.Connect();
return _myGraphClient;
}
我的查询:
MyGraphClient.Cypher
.Match(match).Where((T a) => a.UUID == id)
.With("b")
.CurrentUser(CurrentUsername)
.WhereReadClause("b", GetDomainsClause("b"), CurrentUsername, CurrentRole, direction)
.Return(b => b.As<T>()).Results;
第二个异常:
Neo4jClient.Transactions.TransactionManager.EnqueueCypherRequest(String commandDescription, IGraphClient graphClient, CypherQuery query) in D:\temp17fa3\Neo4jClient.Full\Transactions\TransactionManager.cs:line 229
在 Neo4jClient.GraphClient.PrepareCypherRequest[TResult](CypherQuery 查询,IExecutionPolicy 策略)在 D:\temp17fa3\Neo4jClient.Shared\GraphClient.cs:line 871
在 Neo4jClient.GraphClient.d__881.MoveNext() in D:\temp17fa3\Neo4jClient.Shared\GraphClient.cs:line 967
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter
1.GetResult()
在 Mandarim.Storage.Neo4j.Manager.ManagerBase`1.d__113.MoveNext() 中 P:\Desenvolvimento\branchs\builder-3.0\Mandarim.Storage.Neo4j\Manager\ManagerBase.cs:line 2067
当我们在这里使用异步 api 进行多事务处理时会出现问题。
Neo4jClient 代码上的 [TreadStartic] 不能很好地使用异步方法...所以我改为使用 AsyncLocal。
更多信息可以在这里获取:https://github.com/Readify/Neo4jClient/pull/209
有时在 Neo4jClient 中我会收到此错误。我试图调查问题出在哪里,但我没有找到任何原因。有没有人有同样的问题或者可以帮助我?
谢谢
{"Message":"An error has occurred.","ExceptionMessage":"Object reference not set to an instance of an object.","ExceptionType":"System.NullReferenceException","StackTrace":" 在
Neo4jClient.GraphClient.Neo4jClient.IRawGraphClient.ExecuteGetCypherResults[TResult](CypherQuery 查询) in D:\temp17fa3\Neo4jClient.Shared\GraphClient.cs:line 919\r\n at
Mandarim.Storage.Neo4j.Manager.ManagerBase1.GetNodesRelatedOrderBy(String match, String id, String relationNodeType, String propertyOrderBy, Int32 skip, Int32 take, Direction direction,
Boolean distinct, Expression
1 其中)在 P:\Desenvolvimento\branchs\builder-3.0\Mandarim.Storage.Neo4j\Manager\ManagerBase.cs:line 2105\r\n在
Mandarim.Storage.Neo4j.Manager.ManagerBase1.GetNodesRelatedOrderBy(String id, Labels labelin, Labels labelout, String relationTypes, String propertyOrderBy, Int32 skip, Int32 take, Boolean
distinct, Expression
1 where, Direction direction) in P:\Desenvolvimento\branchs\builder-3.0\Mandarim.Storage.Neo4j\Manager\ManagerBase.cs:line 900\r\n 在
Mandarim.Factory.Base.FactoryBase1.GetNodesRelatedOrderBy(String id, Labels labelin, Labels labelout, String relationTypes, String propertyOrderBy, Int32 skip, Int32 take, Boolean distinct,
Expression
1 where, Direction direction) in P:\Desenvolvimento\branchs\builder-3.0\Mandarim.Factory\Base\FactoryBase.cs:line 177\r\n at
PackDocs.Services.Storage.MandarimStorageServices1.GetNodesRelatedOrderBy(String id, Labels labelin, Labels labelout, String propertyOrderBy, Int32 skip, Int32 take, Boolean distinct,
Expression
1 其中,Direction 方向,RelationTypes[] relationNodeType) in P:\Desenvolvimento\branchs\builder-3.0\Packdocs.Services.Storage\MandarimStorageServices.cs:line 292\r\n
在 Mandarim.PackDocs.Services.ManagerObjects.ManagerProject.GetProjects(Int32 skip, Int32 take, String orderby, CreatedState state) in
P:\Desenvolvimento\branchs\builder-3.0\PackDocs.Services\ManagerObjects\ManagerProject.cs:行 116\r\n 在 PackDocs.OWIN.Services.Host.Controllers.ProjectsController.GetProjects(Int32
skip, Int32 take, String orderby, CreatedState state) in P:\Desenvolvimento\branchs\builder-3.0\Packdocs.OWIN.Services.Host\Controllers\v2\ProjectsController.cs:line 103\r\n at
lambda_method(Closure , Object , Object[] )\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.b__9(Object instance, Object[]
methodParameters)\r\n 在 System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken
cancellationToken)\r\n--- 从先前抛出异常的位置开始的堆栈跟踪结束 ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)\r\n 在
System.Web.Http.Controllers.ApiControllerActionInvoker.d__0.MoveNext()\r\n--- 从先前抛出异常的位置开始的堆栈跟踪结束 ---\r\n at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)\r\n 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)\r\n 在
System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext()\r\n--- 从先前抛出异常的位置开始的堆栈跟踪结束 ---\r\n at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)\r\n 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)\r\n 在
System.Web.Http.Filters.AuthorizationFilterAttribute.d__2.MoveNext()\r\n--- 从先前抛出异常的位置开始的堆栈跟踪结束
---\r\n 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)\r\n 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务
任务)\r\n 在 System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()"}
更新
ContainerBuilder _builder = new ContainerBuilder();
_builder
.Register<ITransactionalGraphClient>(context =>
{
try
{
var neo4jUri = GetNeo4jSettingValue("neo4jUri");
var user = GetNeo4jSettingValue("neo4jUser");
var pwd = GetNeo4jSettingValue("neo4jPassword");
ITransactionalGraphClient graphClient = new GraphClient(new Uri(neo4jUri), user, pwd);
graphClient.Connect();
graphClient.JsonConverters.Add(new DictionaryConverter());
graphClient.JsonConverters.Add(new DateTimeConverter());
graphClient.JsonConverters.Add(new CommonDeserializerMethods());
return graphClient;
}
catch (Exception e)
{
Trace.TraceError(e.ToString());
throw e;
}
}).SingleInstance();
_container = _builder.Build();
获取实例
try
{
_myGraphClient = _myGraphClient ?? AutofacNeo4j.Container.Resolve<ITransactionalGraphClient>();
if (_myGraphClient != null && !_myGraphClient.IsConnected)
_myGraphClient.Connect();
return _myGraphClient;
}
catch (Exception e)
{
Trace.TraceError(e.ToString());
_myGraphClient = _myGraphClient ?? AutofacNeo4j.Container.Resolve<ITransactionalGraphClient>();
_myGraphClient.Connect();
return _myGraphClient;
}
我的查询:
MyGraphClient.Cypher
.Match(match).Where((T a) => a.UUID == id)
.With("b")
.CurrentUser(CurrentUsername)
.WhereReadClause("b", GetDomainsClause("b"), CurrentUsername, CurrentRole, direction)
.Return(b => b.As<T>()).Results;
第二个异常:
Neo4jClient.Transactions.TransactionManager.EnqueueCypherRequest(String commandDescription, IGraphClient graphClient, CypherQuery query) in D:\temp17fa3\Neo4jClient.Full\Transactions\TransactionManager.cs:line 229
在 Neo4jClient.GraphClient.PrepareCypherRequest[TResult](CypherQuery 查询,IExecutionPolicy 策略)在 D:\temp17fa3\Neo4jClient.Shared\GraphClient.cs:line 871
在 Neo4jClient.GraphClient.d__881.MoveNext() in D:\temp17fa3\Neo4jClient.Shared\GraphClient.cs:line 967
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter
1.GetResult()
在 Mandarim.Storage.Neo4j.Manager.ManagerBase`1.d__113.MoveNext() 中 P:\Desenvolvimento\branchs\builder-3.0\Mandarim.Storage.Neo4j\Manager\ManagerBase.cs:line 2067
当我们在这里使用异步 api 进行多事务处理时会出现问题。 Neo4jClient 代码上的 [TreadStartic] 不能很好地使用异步方法...所以我改为使用 AsyncLocal。
更多信息可以在这里获取:https://github.com/Readify/Neo4jClient/pull/209