You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello. I'm curious as to why IReadOnlyList and other interfaces that implement IEnumerable (such as IReadOnlyCollection) do not get deserialized correctly. I see this code here we exactly check for type List and IEnumerable.
This is the error I get when I try to deserialize to Person from neo4j.
---> System.MissingMethodException: Cannot dynamically create an instance of type 'System.Collections.Generic.IReadOnlyList`1[System.String]'. Reason: Cannot create an instance of an interface.
at System.RuntimeType.ActivatorCache..ctor(RuntimeType rt)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
at Neo4jClient.Serialization.CommonDeserializerMethods.CreateAndMap(DeserializationContext context, Type type, JToken element, IEnumerable`1 typeMappings, Int32 nestingLevel)
at Neo4jClient.Serialization.CommonDeserializerMethods.CoerceValue(DeserializationContext context, PropertyInfo propertyInfo, JToken value, IEnumerable`1 typeMappings, Int32 nestingLevel)
at Neo4jClient.Serialization.CommonDeserializerMethods.SetPropertyValue(DeserializationContext context, Object targetObject, PropertyInfo propertyInfo, JToken value, IEnumerable`1 typeMappings, Int32 nestingLevel)
at Neo4jClient.Serialization.CommonDeserializerMethods.Map(DeserializationContext context, Object targetObject, JToken parentJsonToken, IEnumerable`1 typeMappings, Int32 nestingLevel)
at Neo4jClient.Serialization.CommonDeserializerMethods.CreateAndMap(DeserializationContext context, Type type, JToken element, IEnumerable`1 typeMappings, Int32 nestingLevel)
at Neo4jClient.Serialization.CypherJsonDeserializer`1.<>c__DisplayClass20_0.<ParseInSingleColumnMode>b__3(JArray row)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.ToArray()
at Neo4jClient.Serialization.CypherJsonDeserializer`1.Deserialize(String content, Boolean isHttp)
Workaround
My current workaround is to create a custom JsonConverter, however, it does not work when I use it with [JsonConverter] attribute. It does work if I add the converter to the client. This is what I mean.
publicclassPerson{// This does not work. Get the same error above.// Do you have any idea why this doesn't work?[JsonConverter(typeof(IReadOnlyListJsonConverter))]publicIReadOnlyList<string> Names {get;set;}}// This DOES workvarboltClient=new BoltGraphClient(driver);
boltClient.JsonConverters.Add(new IReadOnlyListJsonConverter());
The text was updated successfully, but these errors were encountered:
Hello. I'm curious as to why
IReadOnlyList
and other interfaces that implementIEnumerable
(such asIReadOnlyCollection
) do not get deserialized correctly. I see this code here we exactly check for typeList
andIEnumerable
.Neo4jClient/Neo4jClient/Serialization/CommonDeserializerMethods.cs
Lines 249 to 256 in 28c9480
Example
This is the error I get when I try to deserialize to
Person
from neo4j.Workaround
My current workaround is to create a custom
JsonConverter
, however, it does not work when I use it with[JsonConverter]
attribute. It does work if I add the converter to the client. This is what I mean.The text was updated successfully, but these errors were encountered: