Gravatar for jim.schram@aurora.org

Question by jimschram, Jul 28, 2015 4:43 AM

Call to SitecoreUtilities.ToCoveoFieldName() generating exception

We are using Sitecore 7.5 deployed with CM & CD farms in Azure along with Coveo for Sitecore 3.0.1016.0.

There are two "web" indexes: CoveoCMwebindex and CoveoCDwebindex; both of which are maintained on the CM envirionment as items are published to the respective "web" databases for each farm.

We have the following four lines of code that are calling ToCoveoFieldName():

        var itemPath = SitecoreUtilities.ToCoveoFieldName("_path");
        var latestVersion = SitecoreUtilities.ToCoveoFieldName("_latestversion");
        var datasource = SitecoreUtilities.ToCoveoFieldName("_datasource");
        var fullPath = SitecoreUtilities.ToCoveoFieldName("fullpath");

We are seeing repeated exceptions within GetFieldNameTranslator() the p_Index cannot be null. Here's a complete exception:

        Event code: 3005 
        Event message: An unhandled exception has occurred. 
        Event time: 7/28/2015 5:58:09 AM 
        Event time (UTC): 7/28/2015 5:58:09 AM 
        Event ID: 4633cd8365ef443886dcc3330d434e64 
        Event sequence: 22 
        Event occurrence: 1 
        Event detail code: 0 

        Application information: 
            Application domain: /LM/W3SVC/2051247599/ROOT-1-130825365626609127 
            Trust level: Full 
            Application Virtual Path: / 
            Application Path: E:\approot\ 
            Machine name: XXXXXXX 

        Process information: 
            Process ID: 4644 
            Process name: w3wp.exe 
            Account name: NT AUTHORITY\NETWORK SERVICE 

        Exception information: 
            Exception type: ArgumentNullException 
            Exception message: Precondition failed: The parameter 'p_Index' must not be null
        Parameter name: p_Index
           at Coveo.Framework.CNL.Precondition.NotNull(Object p_Parameter, String p_ParameterName)
           at Coveo.UI.Helpers.SitecoreHelper.GetFieldNameTranslator(ISearchIndex p_Index)
           at Coveo.UI.Helpers.FieldHelper.ToCoveoFieldName(IIndexable p_Indexable, String p_SitecoreField, Boolean p_UsePrefix)
           at XXXXXXXXX.Web.SearchIndices.testing.Services.CoveoSearchProvider.GetResult(CoveoSearchParams searchParams)
           at XXXXXXXXX.Web.Controllers.AhcoSearchRenderingsController.GetSearchResults(String searchQuery, String refinement, Nullable`1 currentPage)
           at XXXXXXXXX.Web.Controllers.AhcoSearchRenderingsController.SearchDetailed(String searchQuery, Nullable`1 currentPage)
           at lambda_method(Closure , ControllerBase , Object[] )
           at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
           at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
           at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
           at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
           at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
           at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
           at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)



        Request information: 
            Request URL: https://XXXXXXXX/api/sitecore/XXXXXXX/SearchDetailed 
            Request path: /api/sitecore/XXXXXXXX/SearchDetailed 
            User host address: XXXXXXX
            User: extranet\Anonymous 
            Is authenticated: False 
            Authentication Type:  
            Thread account name: NT AUTHORITY\NETWORK SERVICE 

        Thread information: 
            Thread ID: 40 
            Thread account name: NT AUTHORITY\NETWORK SERVICE 
            Is impersonating: False 
            Stack trace:    at Coveo.Framework.CNL.Precondition.NotNull(Object p_Parameter, String p_ParameterName)
           at Coveo.UI.Helpers.SitecoreHelper.GetFieldNameTranslator(ISearchIndex p_Index)
           at Coveo.UI.Helpers.FieldHelper.ToCoveoFieldName(IIndexable p_Indexable, String p_SitecoreField, Boolean             p_UsePrefix)
           at XXXXXXXXX.Web.SearchIndices.testing.Services.CoveoSearchProvider.GetResult(CoveoSearchParams searchParams)
           at XXXXXXXXX.Web.Controllers.AhcoSearchRenderingsController.GetSearchResults(String searchQuery, String refinement, Nullable`1 currentPage)
           at XXXXXXXXX.Web.Controllers.AhcoSearchRenderingsController.SearchDetailed(String searchQuery, Nullable`1 currentPage)
           at lambda_method(Closure , ControllerBase , Object[] )
           at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
           at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
           at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
           at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
           at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
           at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
           at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)

Any ideas what might be causing GetSearchIndex() within ToCoveoFieldName() to return null?

Thanks, Jim

Gravatar for jim.schram@aurora.org

Comment by jimschram, Jul 28, 2015 4:45 AM

I should also mention that this code is working in our CM environment, but not in our CD environment.

Gravatar for ncipollina@captechconsulting.com

Comment by ncipollina, Jan 27, 2016 7:53 AM

Did you ever get an answer? I'm seeing the exact same thing in a new setup. I'm seeing this error in CD but not in CM.

1 Reply
Gravatar for lbergeron@coveo.com

Answer by Luc Bergeron, Jul 28, 2015 9:44 AM

Hi,

The first thing I think of is about the way you call the ToCoveoFieldName method. In Sitecore, there are only two ways to find a search index. You need to either specify the index name or provide an IIndexable instance to get the search index that handles it. In Coveo, this second technique is used. To do so, it gets the current database. Then it finds its root item and finally, based on the Sitecore API, gets the Coveo index that handles the item.

If, for some reason, the database's root item is excluded from the search indexes, then this process is unable to resolve the search index and will return null.

It is strongly recommended to provide an IIndexable instance when calling the SitecoreUtilities.ToCoveoFieldName method. When calling the ToCoveoFieldName method from the MVC model instance, the item being rendered is used to resolve the search index.

So, if some items are excluded from the indexes, you can still add a custom processor to the coveoGetContextCoveoIndex pipeline. This pipeline is invoked while resolving the Coveo search index for a specific IIndexable instance. It would allow you to choose which index you want to use. Basically, a processor receives an IIndexable instance and returns the corresponding index name.

I hope this helps

Gravatar for jflheureux@coveo.com

Comment by Jean-François L'Heureux, Aug 4, 2015 5:30 PM

In addition to Luc's answer, note that modifying the indexes <Root> element value is not recommended with Coveo for Sitecore because it prevents Coveo's code to get the IIndexable of the database root item (/sitecore). You should leave the <Root> property default value (/sitecore) and filter indexed items with inbound filtering and/or at query time instead.

Ask a question