Custom Search Index Module Not Working

Adam Hutchinson asked on May 25, 2022 12:45

Hi everyone,

I'm currently using Kentico 11 to try and implement a Search index with custom fields pulling in. For some reason my Custom Module code isn't running - I've followed the tutorials on here but unfortunately the code just isn't running. Below is my code, I can't see anything in the Event Logs to suggest that it's not working, I've tried both with and without the AssemblyDiscoverable attribute, with and without a namespace.

using CMS;
using CMS.DataEngine;
using CMS.DocumentEngine;
using CMS.Membership;
using Models.Models;

// Registers the custom module into the system
[assembly: RegisterModule(typeof(VNCustomSearchIndexModule))]
[assembly: AssemblyDiscoverable]
public class VNCustomSearchIndexModule : Module
    public VNCustomSearchIndexModule() : base(typeof(VNCustomSearchIndexModule).Name, false) { }

    protected override void OnInit()

        // Assigns a handler to the GetContent event for pages
        DocumentEvents.GetContent.Execute += OnGetPageContent;

    private void OnGetPageContent(object sender, DocumentSearchEventArgs e)
        TreeNode indexedPage = e.Node;

        Accommodation accommodation = e.Node as Accommodation;
        Attraction attraction = e.Node as Attraction;

        if (indexedPage != null)
            UserInfo pageOwner = UserInfoProvider.GetUserInfo(indexedPage.NodeOwner);

            if (pageOwner != null)
                e.Content += " " + pageOwner.UserDescription + " ";

Any and all help would be greatly appreciated.

Thanks, Adam

Correct Answer

Adam Hutchinson answered on May 25, 2022 14:00

So, we fixed it!

The solution was as follows:

Move the class from within the App_Code into a separate project, remade the class as when a class is created in the App_Code folder the build action doesn't create the exact right format. Once this was moved and recreated the methods run as intended.

The moral of the story - don't put classes in the App_Code folder, put them in another Project and run them from there.

0 votesVote for this answer Unmark Correct answer

Recent Answers

Juraj Ondrus answered on May 25, 2022 13:14

Try adding the [assembly: AssemblyDiscoverable] into the \ < CustomAssemblyProject >\Properties\AssemblyInfo.cs file.

0 votesVote for this answer Mark as a Correct answer

Adam Hutchinson answered on May 25, 2022 13:16

I can confirm that this is what the AssemblyInfo.cs file looks like

using System.Reflection;
using System.Runtime.InteropServices;
using System.Security;
using CMS;

[assembly: AssemblyTitle("VisitNorthumberland.Web")]
[assembly: AssemblyDescription("VisitNorthumberland.Web")]

[assembly: ComVisible(false)]
[assembly: Guid("3d5900ae-111a-45be-96b3-d9e4606ca793")]
[assembly: AllowPartiallyTrustedCallers]
[assembly: SecurityRules(SecurityRuleSet.Level1)]

[assembly: AssemblyDiscoverable]
0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on May 25, 2022 13:24

I assume the cross references are added in the solution - to the CMSApp. Is the custom DLL being created in the BIN folder after rebuilding? If not, then the solution is not recognizing the custom assembly project. I would may try using
public VNCustomSearchIndexModule() : base("someCustomName") { }
instead, just to see if it makes any difference.

0 votesVote for this answer Mark as a Correct answer

Adam Hutchinson answered on May 25, 2022 13:28 (last edited on May 25, 2022 13:30)

There is no custom DLL in the project bin, I can confirm that I have now tried:

public VNCustomSearchIndexModule() : base("customSearchModuleForMyWebsite", false) { }

This file is currently located in the root project at ~/App_Code/CMSmodules/NameOfMyClass.cs

Do I need to perform anything within the CMS, I have not done anything in the CMS as I was just hoping to hook into the events when the Search Index was/is generating.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.