1

I'm trying to create a custom predicate to search a particular profile in a contact's profile using Sitecore 9.0.1.

Here's the code:

public class ContactProfilMatches : ICondition, IContactSearchQueryFactory
{
    public string MatchingPatternId { get; set; }

    public StringOperationType Comparison { get; set; }

    public bool Evaluate(IRuleExecutionContext context)
    {
        Contact contact = context.Fact<Contact>();

        if (contact == null)
        {
            return false;
        }

        ContactBehaviorProfile contactProfiles = contact.GetFacet<ContactBehaviorProfile>(ContactBehaviorProfile.DefaultFacetKey);

        return contactProfiles.Scores.Any(s => s.Key == MatchingPatternId.ToGuid() && s.Value.MatchedPatternId == MatchingPatternId.ToGuid()) 
               && contact.Interactions.Any();
    }

    public Expression<Func<Contact, bool>> CreateContactSearchQuery(IContactSearchQueryContext context)
    {
        return contact =>
            contact.GetFacet<ContactBehaviorProfile>(ContactBehaviorProfile.DefaultFacetKey).Scores
                .Any(s => s.Key == MatchingPatternId.ToGuid() && s.Value.MatchedPatternId == MatchingPatternId.ToGuid())
            && contact.InteractionsCache().InteractionCaches.Any();
    }
}

So to validate if it works I set a breakpoint in my CreateContactSearchQuery method and, through the ListManager view, create a segmented list through all my contacts with profile ID x. The predicate has previously been set in content editor beneath the rules.

I then attach myself to my webApp (Azure), then proceed to check if it works. Breakpoint is hit. F10, the request executes, F10 it then goes out of the method. So far so good. But as soon as it exits there's an exception:

Exception: System.Web.HttpUnhandledException
Message: Exception of type 'System.Web.HttpUnhandledException' was thrown.
Source: System.Web
   at System.Web.UI.Page.HandleError(Exception e)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest()
   at System.Web.UI.Page.ProcessRequest(HttpContext context)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Nested Exception

Exception: System.Reflection.TargetInvocationException
Message: Exception has been thrown by the target of an invocation.
Source: mscorlib
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Sitecore.Reflection.ReflectionUtil.InvokeMethod(MethodInfo method, Object[] parameters, Object obj)
   at Sitecore.Nexus.Pipelines.NexusPipelineApi.Resume(PipelineArgs args, Pipeline pipeline)
   at Sitecore.Web.UI.Sheer.ClientPage.ResumePipeline()
   at Sitecore.Web.UI.Sheer.ClientPage.OnPreRender(EventArgs e)
   at System.Web.UI.Control.PreRenderRecursiveInternal()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Nested Exception

Exception: Sitecore.XConnect.XdbSearchUnavailableException
Message: The HTTP response was not successful: InternalServerError
Source: Sitecore.Xdb.Common.Web
   at Sitecore.Xdb.Common.Web.Synchronous.SynchronousExtensions.SuspendContextLock[TResult](Func`1 taskFactory)
   at Sitecore.XConnect.Client.XConnectSynchronousExtensions.SuspendContextLock[TResult](Func`1 taskFactory)
   at Sitecore.XConnect.Client.XConnectSynchronousExtensions.GetBatchEnumeratorSync[TEntity](IAsyncQueryable`1 asyncQueryable, Int32 defaultBatchSize)
   at Sitecore.XConnect.Segmentation.SegmentationEngine.<>c.<CountContacts>b__24_0(IAsyncQueryable`1 contacts)
   at Sitecore.XConnect.Segmentation.SegmentationEngine.PerformSearch[T](IContactSearchQueryFactory queryFactory, Func`2 searchWork, Byte[] syncToken, ContactExpandOptions expandOptions)
   at Sitecore.XConnect.Segmentation.SegmentationEngine.CountContacts(IContactSearchQueryFactory queryFactory)
   at Sitecore.Shell.Applications.Analytics.SegmentBuilder.SegmentBuilderForm.EditFilterCondition(ClientPipelineArgs args)

Most other posts were talking of checking the certificate in case where an ForbiddenAccess exception was thrown, but it is not the case right now. I've tried accessing the logs to get any additionnal info, but no luck... what's going on?

2
  • Any error in the xConnect logs? Your rule code seems fine to me. – Chris Auer Dec 21 '19 at 2:49
  • @ChrisAuer I'll try to find them but in Azure it's kinda hard. – hsim Jan 6 '20 at 14:02

Your Answer

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

Browse other questions tagged or ask your own question.