Neo4jClient 无法反序列化为您提供的对象结构(参数 'content'),System.ArgumentNullException (参数 'input')



我是Neo4jClient的新手,我似乎不能得到一个简单的查询工作。

I have class:

public class User
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string Gender { get; set; }
public DateTime DateOfBirth { get; set; }
public DateTime DateOfEnrollment { get; set; }
}

插入到数据库的工作原理:

_graphClient
.Cypher
.Create("(user:User $user)")
.WithParam("user", user)
.ExecuteWithoutResultsAsync()
.Wait();

其中_graphClient只是一个具有JsonContractResolver = CamelCasePropertyNamesContractResolver()的普通GraphClient。

但是,当我尝试返回所有User节点时:

var query = _graphClient
.Cypher
.Match("user:User")
.Return<User>("user");
var result = await query.ResultsAsync;

我得到以下错误:

An unhandled exception has occurred while executing the request.
System.ArgumentException: Neo4j returned a valid response, however Neo4jClient was unable to deserialize into the object structure you supplied.
First, try and review the exception below to work out what broke.
If it's not obvious, you can ask for help at http://stackoverflow.com/questions/tagged/neo4jclient
Include the full text of this exception, including this message, the stack trace, and all of the inner exception details.
Include the full type definition of Project.Models.User.
Include this raw JSON, with any sensitive values replaced with non-sensitive equivalents:
(Parameter 'content')
---> System.ArgumentNullException: Value cannot be null. (Parameter 'input')
at System.Text.RegularExpressions.ThrowHelper.ThrowArgumentNullException(ExceptionArgument arg)
at System.Text.RegularExpressions.Regex.Replace(String input, String replacement)
at Neo4jClient.Serialization.CommonDeserializerMethods.ReplaceAllDateInstancesWithNeoDates(String content)
at Neo4jClient.Serialization.CypherJsonDeserializer`1.Deserialize(String content, Boolean isHttp)
--- End of inner exception stack trace ---
at Neo4jClient.Serialization.CypherJsonDeserializer`1.Deserialize(String content, Boolean isHttp)
at Neo4jClient.GraphClient.Neo4jClient.IRawGraphClient.ExecuteGetCypherResultsAsync[TResult](CypherQuery query)
at Project.Repositories.UserRepository.GetAllUsers() in C:CodeProjectRepositoriesUserRepository.cs:line 27
at Project.Controllers.UserController.Get() in C:CodeProjectControllersUserController.cs:line 26
at lambda_method5(Closure , Object )
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

从User类型中删除DateTime并不能解决问题。

我不确定错误来自哪里,我将在下面的代码在LinqPad中工作(并且应该是正常的c#应用程序)。我已经尝试了BoltGraphClientGraphClient-我没有得到任何错误。

我试过从DB中删除DateTimeint属性,但它只是简单地恢复到default()的这些值。

你可以试试下面的代码,看看它是否有效-我看不出你的代码有什么明显的问题-它看起来绝对没问题。


async Task Main()
{
var boltClient = new BoltGraphClient("neo4j://localhost:7687", "neo4j", "neo");
boltClient.JsonContractResolver = new CamelCasePropertyNamesContractResolver();
await boltClient.ConnectAsync();
await DoActions(boltClient, "BOLT");

var httpClient = new GraphClient(new Uri("http://localhost:7474"), "neo4j", "neo");
httpClient.JsonContractResolver = new CamelCasePropertyNamesContractResolver();
await httpClient.ConnectAsync();

await DoActions(boltClient, "HTTP");
}
public async Task DoActions(IGraphClient client, string type)
{
Console.WriteLine($"Performing actions using {type} type of connection.");
await ClearUsers(client);
await CreateUser(client);

var users = await GetUsers(client);
WriteUsers(users);
}
public void WriteUsers(IEnumerable<User> users){
Console.WriteLine("Users");
foreach (var user in users)
{
Console.WriteLine($"t{user.Id}: {user.FirstName} {user.LastName} ({user.Gender}), {user.Email}, {user.DateOfBirth}, {user.DateOfEnrollment}");
}
}
public async Task<IEnumerable<User>> GetUsers(IGraphClient graphClient)
{
var query = graphClient
.Cypher
.Match("(user:User)")
.Return<User>("user");
return await query.ResultsAsync;
}
public async Task ClearUsers(IGraphClient graphClient)
{
await graphClient.Cypher
.Match("(u:User)")
.Delete("u")
.ExecuteWithoutResultsAsync();
}
public async Task CreateUser(IGraphClient graphClient)
{
var user = new User
{
Id = 1,
FirstName = "Charlotte",
LastName = "Skardon",
DateOfBirth = DateTime.Now,
DateOfEnrollment = DateTime.Now.AddDays(3),
Email = "a@a.com",
Gender = "F"
};
await graphClient
.Cypher
.Create("(user:User $user)")
.WithParam("user", user)
.ExecuteWithoutResultsAsync();      
}

public class User
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string Gender { get; set; }
public DateTime DateOfBirth { get; set; }
public DateTime DateOfEnrollment { get; set; }
}

相关内容

  • 没有找到相关文章

最新更新