Unable to implement abstract CriterionBase class in EPiServer

This article was migrated from an older iteration of our website, and it could deviate in design and functionality.


We ran into a rather peculiar problem when implementing custom visitor group criteria in EPiServer - we simply couldn't implement the abstract IsMatch member of the CriterionBase class.

Estimated read time : 3 minutes

Jump to

Implementing visitor group criterion in EPiServer

We’re working on an EPiServer CMS 6 R2 site where custom visitor group criteria are being implemented. However, we ran into a rather peculiar problem in Visual Studio. In short we were unable to compile the project because of the following rather contradictory error messages:

‘Website.UserAgentCriterion.IsMatch(System.Security.Principal.IPrincipal,
System.Web.HttpContextBase)’: no suitable method found to override

And here’s the funny part - it’s followed by the following error:

‘Website.UserAgentCriterion’ does not implement inherited abstract member
‘EPiServer.Personalization.VisitorGroups.UserAgentCriterion
.IsMatch(System.Security.Principal.IPrincipal, System.Web.HttpContextBase)’

In other words, we have to implement the abstract IsMatch() member, but Visual Studio tells us there is no abstract IsMatch() member to override.

Ambiguous naming of System.Web.HttpContextBase

The error messages are actually a bit misleading. The reason this fails is because EPiServer has built the CriterionBase class using System.Web.HttpContextBase from the System.Web.Abstractions assembly.

You see, there are two HttpContextBase classes available in the same namespace but in different assemblies. One is in the System.Web assembly, and the other in the System.Web.Abstractions assembly.

The solution

To be able to compile your custom visitor group criterion based on CriterionBase you need to add a reference to System.Web.Abstractions.

Further details

After digging into this a bit deeper I found the underlying reason for the confusion: Microsoft seem to have moved HttpContextBase from the System.Web.Abstractions assembly to the System.Web assembly in .NET 4.0 - still with the same namespace.

In .NET 3.5 (the .NET version EPiServer use when building their projects) HttpContextBase was located in the System.Web.Abstractions assembly.

However, since it's located in the commonly referenced System.Web assembly in .NET 4.0 (with the same namespace) you might think you're implementing the correct member signature of CriterionBase when in fact you're not. Sort of. :)

In other words, this issue will only affect projects built on ASP.NET 4.0.