I have an existing application using NHibernate to load some fairly complex objects from a database (SQL Server 2008 R2) that has been running for quite some time.
Today, I'm encountering the following error when trying to use JSON.Net to serialize my object:
Error getting value from 'DefaultValue' on 'NHibernate.Type.DateTimeOffsetType'.
None of the properties in my NHibernate mappings are using the DateTimeOffsetType, so I suspect that NHibernate is proxying my objects' properties to that somehow.
I have several Nullable DateTime values on my object, but nothing new to my current release.
Where should I be looking to figure out what properties NHibernate is trying use that type for?
What else might I be missing? The error comes when I attempt to serialize using this code:
var converter = new IsoDateTimeConverter();
x.Json = JsonConvert.SerializeObject(myObject, converter);
Again, that code has been in place for quite some time, it's just the problem that is new.
Not really the solution you will have been looking for perhaps, but a solution none the less - I encountered something similar. In my case I had forgotten to return my DTO from a web api call and the default json serialiser kicking in did this.
Now I map my data object over to a DTO object which has data contract attributes and I serialize that. Since my DTO is simple and doesn't get NHibernate Proxified this error no longer seems to occur.
Otherwise - I have done this for other Nullable Dates - where I want more control over the serialisation. Define a custom converter for it and do as you wish, but for this Nhibernate Type. I'd prefer not serialising (or trying to) those proxy types at all though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With