2017-05-24 5 views
1

Ich habe in Sitecore 7.2 einen berechneten Feldindex implementiert. Allerdings wird der Index-Manager nun gebrochen und ich bekomme die folgende MeldungUngültige Umwandlung von 'System.String' in 'Sitecore.ContentSearch.ProviderIndexConfiguration'

Invalid cast from 'System.String' to 'Sitecore.ContentSearch.ProviderIndexConfiguration'. 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: System.InvalidCastException: Invalid cast from 'System.String' to 'Sitecore.ContentSearch.ProviderIndexConfiguration'. 

ich die folgende Klasse für mein berechnetes Feld umgesetzt habe:

namespace Computed.Search 
{ 
    public class OfficeLocationComputedField : IComputedIndexField 
    { 
     public string FieldName { get; set; } 
     public string ReturnType { get; set; } 

     public object ComputeFieldValue(IIndexable indexable) 
     { 
      Assert.ArgumentNotNull(indexable, nameof(indexable)); 
      try 
      { 
       var result = new List<string>(); 

       var indexableItem = indexable as SitecoreIndexableItem; 
       if (indexableItem == null) 
        return null; 

       var item = (Item) indexableItem; 

       // Treelist fields map to the MultilistField type as per ~/App_Config/FieldTypes.config 
       MultilistField field = item?.Fields["officelocation"]; 
       if (field == null) 
        return null; 

       var items = field.GetItems(); 
       if (items == null || items.Length == 0) 
        return result; 

       foreach (var locationItem in items) 
       { 
        //result.Add(locationItem.Name); // if you want the name of the item 
        result.Add(locationItem.DisplayName); // if you want the display name of the item 
        //result.Add(locationItem["Title"]); // if you want the value of a field on the item 
       } 

       return result; 

      } 
      catch (Exception exception) 
      { 
       Log.Error($"An Error occured in custom computed index. {exception.Message}", exception); 
      } 
      return null; 
     } 
    } 
} 

und die Konfigurationsdatei ist wie folgt:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"> 
    <sitecore> 
    <contentSearch> 
     <indexConfigurations> 
     <defaultLuceneIndexConfiguration> 
      <fields hint="raw:AddComputedIndexField"> 
      <field fieldName="officelocation" storageType="YES" indexType="TOKENIZED">Computed.Search.OfficeLocationComputedField, Computed</field> 
      </fields> 
     </defaultLuceneIndexConfiguration> 
     </indexConfigurations> 
    </contentSearch> 
    </sitecore> 
</configuration> 

Ich weiß nicht, welchen Fehler ich mache oder was ich noch ändern muss?

Antwort

2

Die Sitecore Invalid cast from 'System.String' to ... Ausnahme in 90% Fällen ist durch die Konfigurationsfehler verursacht.

In Ihrem Fall versucht Sitecore, die Zeichenfolge an ProviderIndexConfiguration zu übergeben. Es ist LuceneIndexConfiguration, die von ProviderIndexConfiguration erbt.

Es sieht so aus, als ob Sitecore den Inhalt der Patch-Datei nicht mit der Lucene-Standardkonfiguration abgleichen kann.

Stellen Sie sicher, dass der Name der Patch-Datei alphabetisch nach Sitecore.ContentSearch.Lucene.DefaultIndexConfiguration.config lautet.

Es ist das Problem weiterhin besteht, fügen Sie type Attribut defaultLuceneIndexConfiguration Tag und setzen Sie ihn auf type="Sitecore.ContentSearch.LuceneProvider.LuceneIndexConfiguration, Sitecore.ContentSearch.LuceneProvider":

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"> 
    <sitecore> 
    <contentSearch> 
     <indexConfigurations> 
     <defaultLuceneIndexConfiguration type="Sitecore.ContentSearch.LuceneProvider.LuceneIndexConfiguration, Sitecore.ContentSearch.LuceneProvider"> 
      <fields hint="raw:AddComputedIndexField"> 
      <field fieldName="officelocation" storageType="YES" indexType="TOKENIZED">Computed.Search.OfficeLocationComputedField, Computed</field> 
      </fields> 
     </defaultLuceneIndexConfiguration> 
     </indexConfigurations> 
    </contentSearch> 
    </sitecore> 
</configuration> 
+0

Ich habe Ihre Vorschläge implementiert, aber leider besteht das Problem weiterhin. Gleiche Ausnahme. – user843681

+0

Können Sie '/ sitecore/admin/showconfig.aspx'-URL öffnen und sehen, was sind alle untergeordneten Knoten von' sitecore/contentSearch/indexConfigurations' Tag? –

+0

Sie können auch versuchen, Ihr Feld in 'Sitecore.ContentSearch.Lucene.DefaultIndexConfiguration.config' anstatt einer benutzerdefinierten Patch-Datei hinzuzufügen, nur um sicherzugehen, dass es sich um ein Konfigurationsproblem und kein Codeproblem handelt. –

0

die älteren Patch-Datei, die ich geschaffen hatte und in alphabetischer Reihenfolge vor dem Sitecore.ContentSearch.Lucene.DefaultIndexConfiguration.conf Ig befand sich immer noch im Ordner Website \ App_Config \ Include. Ich habe vergessen, es zu entfernen. Durch das Entfernen der alten Datei wurde das Problem behoben. Alles funktioniert jetzt.

Verwandte Themen