2

After upgrading to Sitecore 9 and converting custom index files from using Lucene to Solr, I am getting the following error on an Ajax call: Unable to cast object of type 'System.Collections.ArrayList' to type 'System.String'.

[InvalidCastException: Unable to cast object of type 'System.Collections.ArrayList' to type 'System.String'.]
   Sitecore.ContentSearch.Converters.IndexFieldIDValueConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value) +38
   Sitecore.ContentSearch.Converters.IndexFieldStorageValueFormatter.ReadFromIndexStorage(Object indexValue, String fieldName, Type destinationType) +197

[InvalidCastException: Could not convert value of type System.Collections.ArrayList to destination type Sitecore.Data.ID: Unable to cast object of type 'System.Collections.ArrayList' to type 'System.String'.]
   Sitecore.ContentSearch.Converters.IndexFieldStorageValueFormatter.ReadFromIndexStorage(Object indexValue, String fieldName, Type destinationType) +801
   Sitecore.ContentSearch.DocumentTypeMapInfo.SetProperty(Object target, String propertyName, String documentFieldName, Object value) +802

screenshot of error

I have tried an explicit cast and adding multiValued="false" in the config file for some of the fields but I am unsure what is causing the error.

  • Most probably field configuration issue. What are the properties of your search result item? Any of them you expect to be a string with pipe separated guids? – Marek Musielak Oct 10 at 14:39
  • Yes, there are a few fields that can be multiple GUIDs. The error is showing accross the board for different index's, not just the one showed above. – Jamie Oct 10 at 14:49
  • You have a custom index field in C# that is an array in c# and not an array in the config file. – Chris Auer Oct 10 at 15:33
  • Search for guidcollection or stringcollection in sitecore config files and see how sitecore uses them ootb. – Vincent Lui Oct 10 at 16:13
3

You have a custom SearchResultItem that does not match the index config.

You should have a custom class that extends SearchResultItem, like this

public class IndexedItem : SearchResultItem

That class will have a field that is a string like this

[IndexField("PageTitle")]
public string PageTitle { get; set; }

But then in your config you have it specified as a string collection

<fieldMap type="Sitecore.ContentSearch.SolrProvider.SolrFieldMap, Sitecore.ContentSearch.SolrProvider">
    <fieldNames hint="raw:AddFieldByFieldName">
        <field fieldName="pagetitle" returnType="stringCollection" />
    </fieldNames>
</fieldMap>

The crash is when the collection tries to populate a string.

1

I had similar issue while upgrading Sitecore 8.2 with Lucene to Sitecore 9.2 with Solr quick fix which I have done is as below.

  1. I was using a patch config file like Search.config.

  2. The entire format of index which gets build was totally different in Lucene so we changed to match Solr index format.Which is like below.(below is one of the example you need to check everything)

Lucene:

<field fieldName="metatitle" storageType="YES" indexType="TOKENIZED" vectorType="YES" boost="1f" omitNorms="true" type="System.String" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider">

Solr:

<field fieldName="metatitle" returnType="stringArray" settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration, Sitecore.ContentSearch.SolrProvider"/>
  1. I changed code for ComputedIndexField as per Solr, in the class where we are generating these.
  2. One more think which I checked is for how you query the Solr for getting index and Search result is little different, So you may need to modify that also.
  3. Reindexed everything and check that works.

In my case after performing all above steps Solr started responding everything. I thought this will help you.

0

Thanks for all the help, I have now fixed the issue. The problem was in my config files, for each field value the multiValued property was being set to true automatically. This meant that each field that was a string was coming through as an array even though there was only one value. Once I set all of the fields to multiValued="false", the index worked fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.