Gravatar for shirazi@rdacorp.com

Question by aga, Feb 16, 2016 11:48 PM

System.InvalidCastException in logs

Hi

I'm using coveo for sitecore and I just started seeing these warnings in the logs. I dont know whats causing this nor do I know which field. Can anyone help me debug this?

  • Coveo For Sitecore: 1116
  • CES Version: 7.0 x64 Build 7914.0

Here is the exception:

1612 22:59:31 WARN  Field "templateid" could not be mapped to the result type. Field type was "System.Double" and the mapped property did not match the correct type
Exception: System.InvalidCastException
Message: Could not map index document field to property "templateid" on type Sitecore.ContentSearch.SearchTypes.SearchResultItem : Could not convert value of type System.Double to destination type Sitecore.Data.ID : Unable to cast object of type 'System.Double' to type 'System.String'.
Source: Sitecore.ContentSearch
   at Sitecore.ContentSearch.DocumentTypeMapInfo.SetProperty(Object target, String propertyName, String documentFieldName, Object value)
   at Coveo.SearchProvider.CoveoDocumentTypeMapper.ReadDocumentFields[TElement](QueryResult p_Document, IEnumerable`1 p_FieldNames, DocumentTypeMapInfo p_DocumentTypeMapInfo, IEnumerable`1 p_VirtualFieldProcessors, TElement p_Result)

Nested Exception

Exception: System.InvalidCastException
Message: Could not convert value of type System.Double to destination type Sitecore.Data.ID : Unable to cast object of type 'System.Double' to type 'System.String'.
Source: Coveo.Framework
   at Coveo.Framework.Conversion.CoveoIndexFieldStorageValueFormatterBase.ReadFromIndexStorage(Object p_IndexValue, Type p_DestinationType, ITypeDescriptorContext p_Context)
   at Sitecore.ContentSearch.DocumentTypeMapInfo.SetProperty(Object target, String propertyName, String documentFieldName, Object value)

Nested Exception

Exception: System.InvalidCastException
Message: Unable to cast object of type 'System.Double' to type 'System.String'.
Source: Sitecore.ContentSearch
   at Sitecore.ContentSearch.Converters.IndexFieldIDValueConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
   at Coveo.Framework.Conversion.CoveoIndexFieldStorageValueFormatterBase.ReadFromIndexStorage(Object p_IndexValue, Type p_DestinationType, ITypeDescriptorContext p_Context)
1 Reply
Gravatar for lbergeron@coveo.com

Answer by Luc Bergeron, Feb 17, 2016 9:21 AM

Hi,

There are several clues in the stacktrace. The error happens when the search provider is mapping a document returned from the search index to the Sitecore.ContentSearch.SearchTypes.SearchResultItem class. This code is most likely called by a search query performed using LINQ. Unfortunately, the value that comes out of search index is a System.Double when the expected type is Sitecore.Data.ID. In other words, Sitecore fails when trying to map the SearchResultItem.TemplateID property because the value types are not compatible.

My guess is that some of your Sitecore template contains a field named templateid of type Number which is interferring with the SearchResultItem.TemplateID property.

I would suggest to search for any templateid field in your templates and make sure the field types are correct.

I hope this helps

Ask a question