Migrating a package to Umbraco 16 - Index problem with ContentValueSetValidator

I’m trying to install my Forum package into a clean Umbraco 16 project, but it errors when trying to create the indexing, does anyone know how I can resolve this error

commenting out the line doesn’t appear to have any negative effects so far :rofl:

I think you are calling the wrong constructor. ContentValueSetValidator has two constructor, one of which is internal and marked as “Used for tests” and the other one is public. Try calling the public constructor instead. See:

If you want more control, you could go for a custom implementation of IContentValueSetValidator :slight_smile:

What does a ValueSetValidator do? I have build lots of indexes and know how to use ValueSetBuilders, but what is the validator for? Trying to determine if I need it :stuck_out_tongue:

When creating ValueSets the ValueSetValidator checks whether the valueset can be indexed or not which is triggered during (re)indexing (new content, content change, full re-index triggered etc.).
The Umbraco ContentValueSetValidator implementation checks for example:

  • If the path contains the parentId
  • If the item is not in the recycle bin
  • If the item is not protected
  • etc.

These checks result in a ValueSetValidationResult which basically tells if the record should be in the index or not.

When running a custom index you can of course put the logic inside the ValueSetBuilder (I mean, the world is your oyster), but you can also create your own validator and put the logic there.
If you want to add additional checks on top of the default ContentValueSetValidator you can extend it, create an override, call the base checks that you need and add your logic on top of it! :smiley:

I did try that, but that has a mismatch in scopeprovider instances

ConfigureForumIndexOptions gets passed Umbraco.CMS.Infrastructure.Scoping.IScopeProvider but ContentValueSetValidator is expecting Umbraco.CMS.Core.Scoping.IScopeProvider

Do you have any code samples of the usage and arguments of ConfigureForumIndexOptions?

IScopeProvider in your case should come from Umbraco.Cms.Infrastructure.Scoping since ContentValueSetValidator uses this one.
If I check the ContentValueSetValidator (from Umbraco.Cms.Infrastructure.Examine), it shows that it uses the one from Cms.Infrastructure:

It also tells me the Cms.Core is obsolete:

Make sure you have the following ‘using’ in your file:

using Umbraco.Cms.Infrastructure.Scoping;

Please also make sure your NuGets are also up to date (both installed and transative) and are running on 16.
Edit: the ContentValueSetValidator that you mention is the one from Umbraco themselves right, not a custom one with the same name?

I have discovered the problem, my RCL is multi targeting and VS is getting a bit confused.

1 Like

Ah, good to hear you resolved the issue! :grin:

I ended up with this code which works fine now

#if NET9_0 // For Umbraco 15+
                // Code specific to Umbraco 16
                options.Validator = new ContentValueSetValidator(true,false,_publicAccessService,_scopeProvider);  
#else
                options.Validator = new ContentValueSetValidator(true,null,new[] { "forumPost" },null); 
#endif
1 Like