Friday, August 3, 2018

Sitecore Glass Mapper Experience Editor Error with Incorrect Glass Base Class ID Property Type

I was trying to get the Glass Mapper working with Sitecore 9 in Experience Editor mode and it returned following error.


Failed item resolve - You cannot save a class that does not contain a property that represents the item ID. Ensure that at least one property has been marked to contain the Sitecore ID. Type: Castle.Proxies.IPageBaseProxy
at Glass.Mapper.Sc.Configuration.SitecoreTypeConfiguration.ResolveItem(Object target, Database database) in C:\TeamCity\buildAgent\work\66b8bb468d084f35\Source\Glass.Mapper.Sc\Configuration\SitecoreTypeConfiguration.cs:line 214
at Glass.Mapper.Sc.GlassHtml.MakeEditable[T](Expression`1 field, Expression`1 standardOutput, T model, Object parameters, Context context, Database database, TextWriter writer) in C:\TeamCity\buildAgent\work\66b8bb468d084f35\Source\Glass.Mapper.Sc\GlassHtml.cs:line 560




I found an issue created for the same for Glass Mapper and it has mention following as a solution
https://github.com/mikeedwards83/Glass.Mapper/issues/113


Reason

In my Glass base class, I have defined the "Id" property of an item as follows


IGlassBase.cs  
[SitecoreInfo(SitecoreInfoType.OriginatorId)]
Guid Id { get; set; }


But once I have changed the "Id" property use "ID" attribute as follows, everything started to work as expected with a possibility of Experience Editor edits.

IGlassBase.cs   
[SitecoreId]
ID Id { get; set; }




NOTE: Credit of finding the solution should go to the @zbecknell who has written the final answer for that GitHub issue.