Alex KeySmith
Alex KeySmith

Reputation: 17091

JsonConstructor attribute not working for RavenDB

After seeing an error like this:

Unable to find a constructor to use for type XXX. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. Path XX.XX

When attempting to load already persisted data from RavenDB, I attempted to use the [JsonConstructor] however I'm unable to get it to work.

After removing all other constructors to force RavenDB to use my desired constructor (and trying all sorts of other things) it worked, leading me to think the attribute seems to be ignored by RavenDb.

However the RavenDB custom serialization documentation suggests all attributes should work.

Upvotes: 2

Views: 798

Answers (1)

Alex KeySmith
Alex KeySmith

Reputation: 17091

After much research, I came across an unrelated post:

http://issues.hibernatingrhinos.com/issue/RavenDB-3011?preventRedirect=true

The simple problem is that RavenDb has put it's attributes in another namespace, ensure you use

Raven.Imports.Newtonsoft.Json.JsonConstructorAttribute

NOT:

Newtonsoft.Json.JsonConstructorAttribute

Doh!

Upvotes: 3

Related Questions