Fix for Sitefinity Backend Search Bug when Removing Fields from Dynamic Content Types

By October 10, 2014Sitefinity

I ran into an issue in Sitefinity recently, where removing a field from a custom content type caused made the backend search on that type fail. I reproduced this issue on a fresh Sitefinity site, to rule out any potential customizations or changes made in the project I discovered this bug in.

Reproducing the Bug

In a fresh 7.0.5100 Sitefinity install, I created a Speakers module, and a Speaker content type within that module:

01-define-speakers-module

Then I created a couple Speakers, so I had something to search for.

02-create-speakers

Searching for John Doe by email address (“example” in this case) yields the correct result:

03-search-speakers

Now let’s delete “Email” field from the Speaker content type, making sure that “Update widget templates as well” is checked when saving the changes:

04-delete-email-field-1

05-delete-email-field-2

Now let’s try searching again:

06-error

Oops! A JavaScript alert dialog pops up with the message “No ‘Email’ member found in type ‘Telerik.Sitefinity.DynamicTypes.Model.Speakers.Speaker'” instead of a search taking place. According to the error message, Sitefinity is still attempting to reference the now-deleted field of “Email.”

The Fix

After some digging, I found the culprit in one of Sitefinity’s configuration files. The fields that are searched are defined in /App_Data/Sitefinity/Configuration/DynamicModulesConfig.config. There is a node for the custom type (identified by the attribute contentType=”Telerik.Sitefinity.DynamicTypes.Model.Speakers.Speaker”). This node has a child node with an attribute “searchFields.” Even after deleting the field, this still read as:

I removed the deleted field so that Sitefinity stops attempting to search for it:

I then had to restart the web application so that the configuration file changes are re-read by Sitefinity. After doing that and attempting another search, it works!

07-fixed

This was demonstrated in version 7.0.5100 of Sitefinity. I performed the same series of steps in the latest version of Sitefinity at time of writing (7.2.5310), and it exhibited the same behavior. Luckily, the above fix also works in this version.

Wrap Up

This is one of the less painful gotchas that one can come across when developing in Sitefinity, as it requires no code changes to rectify. If you come across this issue in a live environment, a configuration change and a restart is all that’s required to eliminate the issue.

An Aside

It’s important to note that this backend search box is not driven by search indexes created in “Administration -> Search indexes”, but if you have a search index configured to search for a now-deleted custom field, you have update that yourself too!

The following two tabs change content below.