C# 来自'的无效强制转换;System.String';至';Sitecore.ContentSearch.ProviderIndexConfiguration';

C# 来自'的无效强制转换;System.String';至';Sitecore.ContentSearch.ProviderIndexConfiguration';,c#,.net,sitecore,sitecore7.2,C#,.net,Sitecore,Sitecore7.2,我在Sitecore 7.2中实现了一个计算字段索引。然而,索引管理器现在坏了,我得到以下消息 Invalid cast from 'System.String' to 'Sitecore.ContentSearch.ProviderIndexConfiguration'. Description: An unhandled exception occurred during the execution of the current web request. Please review

我在Sitecore 7.2中实现了一个计算字段索引。然而,索引管理器现在坏了,我得到以下消息

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'.
我已经为我的计算字段实现了以下类:

名称空间计算。搜索
{
OfficeLocationComputedField的公共类:IComputedIndexField
{
公共字符串字段名{get;set;}
公共字符串返回类型{get;set;}
公共对象ComputeFieldValue(可索引)
{
Assert.ArgumentNotNull(可索引,nameof(可索引));
尝试
{
var result=新列表();
var indexableItem=可作为SitecoreIndexableItem索引;
if(indexableItem==null)
返回null;
变量项=(项)可索引项;
//根据~/App\u Config/FieldTypes.Config,树列表字段映射到MultilistField类型
MultilistField字段=项?.Fields[“officelocation”];
如果(字段==null)
返回null;
var items=field.GetItems();
if(items==null | | items.Length==0)
返回结果;
foreach(项目中的var locationItem)
{
//result.Add(locationItem.Name);//如果需要项的名称
result.Add(locationItem.DisplayName);//如果需要项目的显示名称
//result.Add(locationItem[“Title”]);//如果需要项上字段的值
}
返回结果;
}
捕获(异常)
{
Log.Error($“自定义计算索引中发生错误。{exception.Message}”,异常);
}
返回null;
}
}
}
配置文件如下:


Computed.Search.OfficeLocationComputedField,已计算

我不知道我犯了什么错误,或者我还需要更改什么?

Sitecore
从“System.String”到…
的无效转换在90%的情况下是由配置错误引起的

在您的情况下,Sitecore尝试将字符串强制转换为
ProviderIndexConfiguration
。它是从
ProviderIndexConfiguration
继承的
LuceIndexConfiguration

看起来Sitecore无法将补丁文件内容与默认Lucene索引配置相匹配

确保修补程序文件名按字母顺序位于
Sitecore.ContentSearch.Lucene.DefaultIndexConfiguration.config
之后

如果问题仍然存在,请将
type
属性添加到
defaultLuceneIndexConfiguration
标记,并将其设置为
type=“Sitecore.ContentSearch.LuceneProvider.LuceneIndexConfiguration,Sitecore.ContentSearch.LuceneProvider”


Computed.Search.OfficeLocationComputedField,已计算

我创建的旧补丁文件,按字母顺序排在Sitecore.ContentSearch.Lucene.DefaultIndexConfiguration.conf之前‌​ig仍在Website\App\u Config\Include文件夹中。我忘了把它取下来。删除那个旧文件修复了这个问题。现在一切正常

我实施了你的建议,但不幸的是,问题依然存在。同样的例外。你能打开
/sitecore/admin/showconfiguration.aspx
url并查看
sitecore/contentSearch/indexConfigurations
标记的所有子节点吗?你也可以尝试将你的字段添加到
sitecore.contentSearch.Lucene.DefaultIndexConfiguration.config
中,而不只是为了测试以确保这是一个配置问题,而不是代码问题。