Yet another reason for OptimisticVerificationException: Row not found exception in Sitefinity

by Vesselin Vassilev


Posted On Jan 20, 2017


You've probably seen it - the infamous OptimisticVerificationException: Row not found exception in Sitefinity.

In some of the older Sitefinity versions it was caused by a bug, later it was discovered it could be caused by the Data caching, but in my recent case (Sitefinity version 9.2) it was caused by something very simple: setting DateTime.MinDate to a DateTime field of a dynamic module type.

My scenario was this: I had a dynamic module type, built with Module Builder and one of the fields was of type DateTime. 

I created an API that could Create/Update items of the above content type and that API can be consumed by external applications. 
So, the external applications would pass the needed parameters and my code would create/update the proper dynamic item - nothing too fancy. 

The issue comes when the external program sends DateTime.MinDate (in C# terms) which corresponds to 01/01/0001 date. 

When the code (or rather OpenAccess) tries to save this date in a field of type DateTime in Sitefinity you get the above OptimisticVerificationException exception.
I bit misleading message, I know. 

I can only assume that the underlying reason for this may be caused by the fact that SqlDateTime min value is 01/01/1753 which is much different from the C# DateTime.MinValue of 01/01/0001

So, be aware when you work with dates in Sitefinity Dynamic Modules - always check if the date you are trying to save is bigger than the SqlDateTime.MinValue.

Copyright © Sitefinity Development