Troubleshooting GlassMapper: Editable Used on a SitecoreIgnored Property

Troubleshooting GlassMapper Editable Used on a SitecoreIgnored Property - Featured Image

A while back, I ran into the following error in the Sitecore logs, which pointed to an issue where GlassMapper was trying to render an editable field on a property marked with the [SitecoreIgnore] attribute:

ERROR Failed to render field
Exception: System.InvalidCastException
Message: Unable to cast object of type 'Glass.Mapper.Sc.Configuration.SitecoreIgnoreConfiguration' to type 'Glass.Mapper.Sc.Configuration.SitecoreFieldConfiguration'.
Source: Glass.Mapper.Sc
at Glass.Mapper.Sc.GlassHtml.MakeEditable[T](Expression`1 field, Expression`1 standardOutput, T model, Object parameters, Context context, Database database, TextWriter writer) in D:\a\Glass.Mapper\Glass.Mapper\Source\Glass.Mapper.Sc\GlassHtml.cs:line 576

At first glance, the solution seems straightforward: either remove the [SitecoreIgnore] attribute from the property or avoid using Editable() for that property, depending on your use case.

However, in my case, the problem was much bigger. There were hundreds of properties marked with [SitecoreIgnore], and just as many Editable() calls scattered throughout the codebase. To make things worse, the error message doesn’t specify which property is causing the issue, making it extremely tedious to identify the root cause manually.

To speed things up, I created a PowerShell script that scans the solution for:

  1. Find all properties decorated with [SitecoreIgnore]
  2. Find all references to those properties used with the GlassMapper Editable() helper in .cshtml files

This script acts as a filter, narrowing down the list of properties to review. With fewer candidates, it’s much easier and faster to locate and fix the offending code.

References

Glass.Mapper.Sc Documentation

Leave a Reply

Your email address will not be published. Required fields are marked *