Try our conversational search powered by Generative AI!

Please use GetContentResult extension method for getting results with content types

Vote:
 

Hello,

After upgrading to the latest version of EPiServer Find we get the error "Please use GetContentResult extension method for getting results with content types". The thing is, the type/types we are searching for are not content types. What changed in the new version?

/Peter

#148687
May 20, 2016 8:30
Vote:
 

By default GetResult validates if you query for something implementing IContentData. This is done to avoid confusion as the queried result from GetContent isn't a true copy of the IContentData in the DB (The serialized object in the index is simply not a full copy of the object. GetContentResult solves this by actually fetching the true object from the db before returning the result). However if you like to override this you can turn off the default TypeValidationConvention by resetting the convention:

client.Conventions.TypeValidationConventions = new TypeValidationConventions();

/Henrik

#148689
May 20, 2016 8:46
Vote:
 

Is this possible to do using the IContentIndexer in a IInitializableModule? Since this error basically occurs in all our queries. And does turning off the default TypeValidationConvention have any side effects?

/Peter

#148692
Edited, May 20, 2016 8:57
Vote:
 

You can do this in an IInitializableModule. It has no side effects, it only disables type validation when using GetResult.

#148695
May 20, 2016 9:28
Vote:
 

Can you please provide a code example? I'm not getting it right.

[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
[InitializableModule]
public class FindConfigModule : IInitializableModule
{
private readonly IContentIndexer client = ContentIndexer.Instance;
public void Initialize(InitializationEngine context)
{
client.Conventions.TypeValidationConventions = new TypeValidationConventions();
}

public void Uninitialize(InitializationEngine context)
{
}

public void Preload(string[] parameters)
{
}
}

#162218
Oct 12, 2016 16:34
Vote:
 

I used the following code(the conventions of the EPiServer.Find.IClient type):

[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
[InitializableModule]
public class FindConfigModule : IInitializableModule
{
    private readonly Injected<EPiServer.Find.IClient> client;
    public void Initialize(InitializationEngine context)
    {
        client.Service.Conventions.TypeValidationConventions = new TypeValidationConventions();  
    }

    public void Uninitialize(InitializationEngine context)
    {
    }
}
#162228
Oct 13, 2016 8:13
Vote:
 

Thank you Peter Emilsson. That works just perfect!

#162231
Oct 13, 2016 10:26
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.