ContentIndexer.Instance.Conventions.ForInstancesOf<ContentPageBase>() threw null reference error after updation of episerver.find to latest version

ash
ash
Vote:
 

ContentIndexer.Instance.Conventions.ForInstancesOf<ContentPageBase>() threw null reference error after updation of episerver.find to latest version

#206678
Aug 28, 2019 14:58
Vote:
 

Hey Ash,

Have you updated its dependencies?

#206680
Edited, Aug 28, 2019 15:19
ash
Vote:
 

No, How to find its dependent packages

#206682
Aug 28, 2019 15:14
Vote:
 

Which is the full stacktrace of the exception? You should always post the full stacktrace of exceptions.

As a side note , in most of the cases you should upgrade EPiServer.Find.Cms, and nuget will update Find & Find.Framework for you.

#206683
Aug 28, 2019 15:22
Vote:
 

Sorry about my confusing comment actually I am asking have you updated this to latest stable update and rebuilt the solution?

And one more thing which  Episerver and Find version you are using?

#206684
Aug 28, 2019 15:23
ash
Vote:
 

Getting below error after updating episerver.find from 13.0.1 to 13.2.2

Object reference not set to an instance of an object.
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.NullReferenceException: Object reference not set to an instance of an object.

Source Error: 


Line 38:             //ContentIndexer.Instance.Conventions.ForInstancesOf<GenericMedia>().ShouldIndex(x => false);
Line 39: 
Line 40:             ContentIndexer.Instance.Conventions.ForInstancesOf<ContentPageBase>().ShouldIndex(x =>
Line 41:             {
Line 42:                 //Start off assuming we'll index this page, but if any of the criteria below are met we'll flag it to not be indexed.

Source File: C:\Episerver\Sites\Heritage\EH Web\EH.Website.v2-MasterLive-Ash-Aug\Heritage.Web.Episerver.Find\SearchConventionInitializationModule.cs    Line: 40 

Stack Trace: 


[NullReferenceException: Object reference not set to an instance of an object.]
   Heritage.Web.Episerver.Find.SearchConventionInitializationModule.ConfigureContainer(ServiceConfigurationContext context) in C:\Episerver\Sites\Heritage\EH Web\EH.Website.v2-MasterLive-Ash-Aug\Heritage.Web.Episerver.Find\SearchConventionInitializationModule.cs:40
   EPiServer.Framework.Initialization.Internal.<>c__DisplayClass4_0.<ConfigureContainer>b__0() +16
   EPiServer.Framework.Initialization.Internal.ModuleNode.Execute(Action a, String key) +52
   EPiServer.Framework.Initialization.Internal.ModuleNode.ConfigureContainer(ServiceConfigurationContext context) +100
   EPiServer.Framework.Initialization.InitializationEngine.ConfigureCurrentModules(Boolean final) +177
   EPiServer.Framework.Initialization.InitializationEngine.ExecuteTransition(Boolean continueTransitions) +115
   EPiServer.Framework.Initialization.InitializationEngine.Initialize() +40
   EPiServer.Framework.Initialization.<>c.<FrameworkInitialization>b__7_0(InitializationEngine e) +9
   EPiServer.Framework.Initialization.InitializationModule.EngineExecute(HostType hostType, Action`1 engineAction) +323
   EPiServer.Framework.Initialization.InitializationModule.FrameworkInitialization(HostType hostType) +170
   EPiServer.Global..ctor() +76
   Heritage.Web.Ui.Public.EPiServerApplication..ctor() +42
   ASP.global_asax..ctor() +56

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
   System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +119
   System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +232
   System.Activator.CreateInstance(Type type, Boolean nonPublic) +83
   System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark) +1117
   System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +124
   System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture) +20
   System.Web.HttpRuntime.CreateNonPublicInstance(Type type, Object[] args) +60
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +263
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296

[HttpException (0x80004005): Exception has been thrown by the target of an invocation.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9922840
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +90
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +261

#206713
Aug 29, 2019 8:50
Vote:
 

It would be easier if you attach a debugger to w3wp and see which is null there. Also it would be interesting to look into 

ContentPageBase
#206715
Aug 29, 2019 9:03
ash
Vote:
 

Thanks Quan

#206716
Aug 29, 2019 9:06
ash
Vote:
 

ContentIndexer.Instance gives null after updation of episerver.find v13.0.1 to v13.2.2.

#206731
Aug 29, 2019 11:13
Vote:
 

You should move your code to apply conventions to Initialize, instead of ConfigureContainer, which is too early. At that point the initialization of ContentIndexer is not completed and it might (and in your case, will), return null.

#206733
Aug 29, 2019 11:21
Vote:
 
    [InitializableModule]
    public class SearchConventionInitializationModule : IConfigurableModule
    {
        public void Initialize(InitializationEngine context)
        {
            //ContentIndexer.Instance is null always
            ContentIndexer.Instance.Conventions.ForInstancesOf<ContentPageBase>().ShouldIndex(x =>
            {
                //Start off assuming we'll index this page, but if any of the criteria below are met we'll flag it to not be indexed.
                var shouldIndex = true;

                //Ignore expired pages.
                if (x.StopPublish != null && x.StopPublish < DateTime.Now)
                {
                    shouldIndex = false;
                }
                //Ignore pages in the recycle bin.
                else if (x.IsDeleted) 
                //else if (x.ContentLink.ID == ContentReference.WasteBasket.ID ||
                    //x.Ancestors().Contains(ContentReference.WasteBasket.ID.ToString()))
                {
                    shouldIndex = false;
                }
                //Ignore pages in admin area (note GetFriendlyUrl() will return the scheme and host name, so can only check if contains this path)
                //DM - put this into a web.config or home page area of page paths to ignore.
                else if (x.ContentLink.GetFriendlyUrl().Contains("/administration/"))
                {
                    shouldIndex = false;
                }

                //DM The page should not be indexed, but in some scenarios it might already be indexed, so try to delete it.
                //Uncomment with the find batches bit when we think more work needs doing on find.
                /*if (!shouldIndex)
                {
                    try
                    {
                        ContentIndexer.Instance.Delete(x);
                    }
                    catch
                    {
                    }
                }*/

                return shouldIndex;
                
            });


            EnableContentAreaIndexing(ContentIndexer.Instance.Conventions);
        }

        /// <summary>
        /// This config is picked up on the website starts.  
        /// The actual ContentIndexer settings here though are used when the Find Content Indexing Job runs.
        /// </summary>
        /// <param name="context"></param>
        public void ConfigureContainer(ServiceConfigurationContext context)
        {           

        }

        private void EnableContentAreaIndexing(IContentIndexerConventions conventions)
        {
            conventions.ShouldIndexInContentAreaConvention = new ContentAreaIndexConvention();
        }

        public void Uninitialize(InitializationEngine context)
        {
            //Add uninitialization logic
        }
    }

Also you should add 

[ModuleDependency(typeof(EPiServer.Find.Cms.Module.IndexingModule))]

to make sure your module is initialized after the Find initialization module 

#206736
Aug 29, 2019 11:27
ash
Vote:
 

Thanks Quan. It works fine

#206737
Aug 29, 2019 11:47