Try our conversational search powered by Generative AI!

Dave Beattie
Mar 16, 2021
  1439
(2 votes)

Episerver Routing Error ‘The routed data is of type..and the binding context data ... is of type ..., neither of which matches the requested type...’

Recently while trying to build an Episerver ecommerce solution I ran into an error with a type mismatch where navigating to any type of node or product failed with a type mismatch.

The ‘requested type’ for each product was always the same class.  I then noticed whenever a new type of product was added, the requested type was always the first type of model alphabetically.

The controller for each node and product type was inheriting from a base controller.

This turned out to be where the problem lay.  Each controller looked ok and seemed to be configured for the relevant model.

However, there was a typo in the inheritance on the base class here, which led to each controller compiling as ContentController<CatalogContentBase>.  Thus when processing the route, episerver was getting confused as to which model it should be resolving the route for, and just took a stab in the dark and grabbed the first model inheriting from CatalogContentBase it could find. 

Changing this to a type parameter constraint, so any class implementing this controller would have to be routing a model implementing catalogContentBase, fixed the error. 

Essentially if you run into this error, check that all your controllers are routing the correct content type, and if there is a base class, ensure this is also configured properly.

Mar 16, 2021

Comments

Please login to comment.
Latest blogs
Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog

Azure AI Language – Abstractive Summarisation in Optimizely CMS

In this article, I show how the abstraction summarisation feature provided by the Azure AI Language platform, can be used within Optimizely CMS to...

Anil Patel | Apr 18, 2024 | Syndicated blog

Fix your Search & Navigation (Find) indexing job, please

Once upon a time, a colleague asked me to look into a customer database with weird spikes in database log usage. (You might start to wonder why I a...

Quan Mai | Apr 17, 2024 | Syndicated blog