Episerver Find - Indexing fails using a PageTypeProperty PropertyDate

Vote:
 

When I Index my site I get this error:

Indexing job [CSKILLS2_CSKILLS2] [Page]: Reindexing completed.
ExecutionTime:
4minutes 43seconds
Number of pages indexed: 3366
Number of page errors:
0
Number of batch errors: 3
An exception occured while indexing (Batch):
Error getting value from 'StartDate' on 'Castle.Proxies.NewsArticleTypeProxy'..
(see log for more information)
An exception occured while indexing (Batch):
Error getting value from 'StartDate' on 'Castle.Proxies.NewsArticleTypeProxy'..
(see log for more information)
An exception occured while indexing (Batch):
Error getting value from 'StartDate' on 'Castle.Proxies.NewsArticleTypeProxy'..
(see log for more information)
Indexing job [CSKILLS2_CSKILLS2] [File]:
Reindexing completed.
ExecutionTime: 0minutes 0seconds
Number of files
indexed: 0

It’s a bit of a strange one as it works when the dateTime is empty and fails when it is populated. I was wondering if there was an issue with the Formatting of the date.
In my C# I have created a PageType class and my PageTypeProperty looks like:
[PageTypeProperty(
            Type = typeof(PropertyDate),
            DisplayInEditMode = true,
            Tab = typeof(NewsTab),
            HelpText = "The start date of the event")
        ]
        public virtual string StartDate { get; set; }
(I have tried a virtual string of DateTime too and this didnt work)
This class, of course then populates the PageTypes in the CMS.
Strange thing is it only fails when any DateTime property has been entered.

 

Thanks

Jon

#65716
Feb 06, 2013 15:37
Vote:
 

Hi Jonathan,

I strongly recommend that you make all properties of value types such as DateTime and int nullable when using Page Type Builder. That’s what maps to how EPiServer stores them, meaning that if you don’t, and there’s no value for a DateTime property you’ll get an exception when you try to access it.  And since Find indexes properties, it will access it.

In other words, this isn't really related to Find, but since Find grabs all pages and indexes all properties you may not have experienced problems with non-nullable value type properties prior to indexing with Find.

As for why things fails when the property has been populated, that's because your code property is a string, and the underlying value is a DateTime which can't be cast to string. Anyhow make the code property a DateTime? and you should be fine :)

#65725
Edited, Feb 06, 2013 16:39
Vote:
 
#65759
Feb 07, 2013 15:58
Vote:
 

Many thanks, that worked a treat.

#65761
Feb 07, 2013 16:29