Reputation: 876
I am getting the following error when I try and get the results from a cyper query in Neo4JClient.
Error:
Neo4jClient encountered an exception while deserializing the response from the server. This is likely a bug in Neo4jClient.
Please open an issue at https://bitbucket.org/Readify/neo4jclient/issues/new
To get a reply, and track your issue, ensure you are logged in on BitBucket before submitting.
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 <>f__AnonymousType3`2[[Neo4jClient.Node`1[[IQS_ACL.Nodes.User, IQS ACL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], Neo4jClient, Version=1.0.0.594, Culture=neutral, PublicKeyToken=null],[Neo4jClient.Node`1[[IQS_ACL.Nodes.SecurityRelationshipObject, IQS ACL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], Neo4jClient, Version=1.0.0.594, Culture=neutral, PublicKeyToken=null]].
Include this raw JSON, with any sensitive values replaced with non-sensitive equivalents:
{
"columns" : [ "Node", "Rels" ],
"data" : [ [ {
"paged_traverse" : "http://localhost:7474/db/data/node/7690/paged/traverse/{returnType}{?pageSize,leaseTime}",
"outgoing_relationships" : "http://localhost:7474/db/data/node/7690/relationships/out",
"data" : {
"Name" : "root"
},
"traverse" : "http://localhost:7474/db/data/node/7690/traverse/{returnType}",
"all_typed_relationships" : "http://localhost:7474/db/data/node/7690/relationships/all/{-list|&|types}",
"all_relationships" : "http://localhost:7474/db/data/node/7690/relationships/all",
"property" : "http://localhost:7474/db/data/node/7690/properties/{key}",
"self" : "http://localhost:7474/db/data/node/7690",
"properties" : "http://localhost:7474/db/data/node/7690/properties",
"outgoing_typed_relationships" : "http://localhost:7474/db/data/node/7690/relationships/out/{-list|&|types}",
"incoming_relationships" : "http://localhost:7474/db/data/node/7690/relationships/in",
"incoming_typed_relationships" : "http://localhost:7474/db/data/node/7690/relationships/in/{-list|&|types}",
"extensions" : {
},
"create_relationship" : "http://localhost:7474/db/data/node/7690/relationships"
}, {
"start" : "http://localhost:7474/db/data/node/7690",
"data" : {
"W" : 3,
"R" : 3,
"ReadablePermissions" : "+R+W",
"X" : 1
},
"property" : "http://localhost:7474/db/data/relationship/9351/properties/{key}",
"self" : "http://localhost:7474/db/data/relationship/9351",
"properties" : "http://localhost:7474/db/data/relationship/9351/properties",
"type" : "SECURITY",
"extensions" : {
},
"end" : "http://localhost:7474/db/data/node/7696"
} ], [ {
"paged_traverse" : "http://localhost:7474/db/data/node/7690/paged/traverse/{returnType}{?pageSize,leaseTime}",
"outgoing_relationships" : "http://localhost:7474/db/data/node/7690/relationships/out",
"data" : {
"Name" : "root"
},
"traverse" : "http://localhost:7474/db/data/node/7690/traverse/{returnType}",
"all_typed_relationships" : "http://localhost:7474/db/data/node/7690/relationships/all/{-list|&|types}",
"all_relationships" : "http://localhost:7474/db/data/node/7690/relationships/all",
"property" : "http://localhost:7474/db/data/node/7690/properties/{key}",
"self" : "http://localhost:7474/db/data/node/7690",
"properties" : "http://localhost:7474/db/data/node/7690/properties",
"outgoing_typed_relationships" : "http://localhost:7474/db/data/node/7690/relationships/out/{-list|&|types}",
"incoming_relationships" : "http://localhost:7474/db/data/node/7690/relationships/in",
"incoming_typed_relationships" : "http://localhost:7474/db/data/node/7690/relationships/in/{-list|&|types}",
"extensions" : {
},
"create_relationship" : "http://localhost:7474/db/data/node/7690/relationships"
}, {
"start" : "http://localhost:7474/db/data/node/7690",
"data" : {
"W" : 3,
"R" : 3,
"ReadablePermissions" : "+R+W",
"X" : 1
},
"property" : "http://localhost:7474/db/data/relationship/9351/properties/{key}",
"self" : "http://localhost:7474/db/data/relationship/9351",
"properties" : "http://localhost:7474/db/data/relationship/9351/properties",
"type" : "SECURITY",
"extensions" : {
},
"end" : "http://localhost:7474/db/data/node/7696"
} ] ]}
Code:
var groups = clientConnection.Cypher
.Start(new { n = "node(" + folderID + ")" })
.Match("n<-[r:SECURITY]-x, x<-[v:IS_MEMBER_OF_GROUP*]-b where b.Name = '"+userName+"'")
.ReturnDistinct((x, r) => new
{
Node = x.As<Node<User>>(),
Rels = r.As<Node<SecurityRelationshipObject>>()
});
var results = groups.Results;
It throws on the .Results();
If I run the query :
START n=node(7706) MATCH n<-[r:SECURITY]-x, x<-[v:IS_MEMBER_OF_GROUP*]-b where b.Name = 'user1' RETURN distinct x AS Node, r AS Rels;
in the console it returns:
Node[7700]{Name:"root"} | :SECURITY[9369] {ReadablePermissions:"+R+W",R:3,W:3,X:1} |
Bitbucket ticket: https://bitbucket.org/Readify/neo4jclient/issue/153/cypher-query-returns-create-bug-exception
Class definitions:
public class User
{
//CMIS Object Properties
public string ObjectId { get; set; }
public string BaseTypeId { get; set; }
public string ObjectTypeId { get; set; }
public IList<string> SecondaryObjectTypeIds { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string CreatedBy { get; set; }
public string CreationDate { get; set; }
public string LastModifiedBy { get; set; }
public string LastModificationDate { get; set; }
public string ChangeToken { get; set; }
}
public class UserGroup
{
//CMIS Object Properties
public string ObjectId { get; set; }
public string BaseTypeId { get; set; }
public string ObjectTypeId { get; set; }
public IList<string> SecondaryObjectTypeIds { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string CreatedBy { get; set; }
public string CreationDate { get; set; }
public string LastModifiedBy { get; set; }
public string LastModificationDate { get; set; }
public string ChangeToken { get; set; }
}
public class RelationshipObject
{
//CMIS Object Properties
public string ObjectId { get; set; }
public string BaseTypeId { get; set; }
public string ObjectTypeId { get; set; }
public Array SecondaryObjectTypeIds { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string CreatedBy { get; set; }
public string CreationDate { get; set; }
public string LastModifiedBy { get; set; }
public string LastModificationDate { get; set; }
public string ChangeToken { get; set; }
//RelationshipObject Properties
public string sourceId { get; set; }
public string targetId { get; set; }
}
public class SecurityRelationshipObject : RelationshipObject
{
//CMIS Object Properties
public IList<string> SecondaryObjectTypeIds { get; set; }
public string ReadablePermissions { get; set; }
public int R { get; set; }
public int W { get; set; }
public int X { get; set; }
}
Relationship definitions:
public class RelationshipUserGroupToFolder: Relationship<SecurityRelationshipObject>, IRelationshipAllowingSourceNode<UserGroup>, IRelationshipAllowingTargetNode<FolderObject>
{
string RelationshipName;
public RelationshipUserGroupToFolder(string RelationshipName, NodeReference targetNode, SecurityRelationshipObject relationshipTypeObject)
: base(targetNode, relationshipTypeObject)
{
this.RelationshipName = RelationshipName;
}
public override string RelationshipTypeKey
{
get { return RelationshipName; }
}
}
public class RelationshipUserGroupToUserGroup : Relationship<RelationshipObject>, IRelationshipAllowingSourceNode<UserGroup>, IRelationshipAllowingTargetNode<UserGroup>
{
string RelationshipName;
public RelationshipUserGroupToUserGroup(string RelationshipName, NodeReference targetNode, RelationshipObject relationshipTypeObject)
: base(targetNode, relationshipTypeObject)
{
this.RelationshipName = RelationshipName;
}
public override string RelationshipTypeKey
{
get { return RelationshipName; }
}
}
There are some different types like RelationshipUserToFolder(security) or RelationshipUserToUseGroup(IS_MEMBER_OF_GROUP)
Upvotes: 1
Views: 153
Reputation: 6270
I'm pretty certain the problem is due to the Rels = ...
bit of code, as I'm pretty certain you are attempting to cast a Relationship
into a Node
and Neo4j doesn't know how to do that. Also, JSON.NET (and by association, neo4jclient) doesn't know how to deserialize the SecurityRelationshipObject
as it (and it's base class) have a property defined of type Array
and IList
, only IEnumerable<>
collections can be deserialized.
To that end, the .ReturnDistinct
should look like this:
/* Rest of query here */
.ReturnDistinct((x, r) => new
{
Node = x.As<Node<User>>(),
Rels = r.As<RelationshipInstance<SecurityRelationshipObject>>()
});
and the data objects should look like:
public class RelationshipObject {
/* Other Properties */
public IEnumerable<string> SecondaryObjectTypeIds { get; set }
}
public class SecurityRelationshipObject : RelationshipObject {
/* Other Properties */
public new IEnumerable<string> SecondaryObjectTypeIds { get;set; }
}
Though obviously, you don't need the property in the 'Security' version as it's already in the base class, but if you do have it, you should use the new
keyword to indicate it is replacing the base class version.
If you've not got anything in those properties it will deserialize fine, which might explain why the Node = x.As<Node<User>>()
is working ok, even though you have an IList<>
there as well.
Below is a small program which when run (Tester.Run()
) should output (Chris has known jeff since yesterday
) - can you try this in a console app and see if it works for you? You should be able to copy / paste it in it's entirety..
using System;
using Neo4jClient;
public static class Tester
{
public static void Run()
{
var client = new GraphClient(new Uri("http://localhost.:7474/db/data"));
client.Connect();
NodeReference<User> rootRef = AddData(client);
var query = client.Cypher.Start(new {n = rootRef})
.Match("n-[r:KNOWS]->other")
.Return((other, r) => new
{
Other = other.As<Node<User>>(),
Knows = r.As<RelationshipInstance<KnowsData>>()
});
var results = query.Results;
foreach (var result in results)
Console.WriteLine("Chris has known {0} since {1}", result.Other.Data.Name, result.Knows.Data.Since);
}
private static NodeReference<User> AddData(IGraphClient client)
{
var chris = new User {Name = "Chris"};
var jeff = new User {Name = "Jeff"};
NodeReference<User> chrisRef = client.Create(chris);
NodeReference<User> jeffRef = client.Create(jeff);
client.CreateRelationship(chrisRef, new Knows(jeffRef, new KnowsData {Since = "Yesterday"}));
return chrisRef;
}
}
public class User { public string Name { get; set; } }
public class KnowsData { public string Since { get; set; } }
public class Knows : Relationship<KnowsData>, IRelationshipAllowingSourceNode<User>, IRelationshipAllowingTargetNode<User>
{
public Knows(NodeReference targetNode, KnowsData data) : base(targetNode, data) {}
public override string RelationshipTypeKey { get { return "KNOWS"; } }
}
Upvotes: 1