Glass.Mapper: You cannot save a class that does not contain a property that represents the item ID

@mikeedwards83

I am getting the following error periodically in Page Editor. Using TDS codegen with the template shown below. In can see that IPromoProxy implements IGlassBase in the codegen file. An IIS reset fixes this for a short period, then it returns. SC 7.2 Update-3 (Glass.Mapper.Sc v3.2.3.49)

See also: http://stackoverflow.com/questions/27574397/sitecore-pageeditor-randomly-shows-error-with-glass-mapper

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.IPromoProxy

 at Glass.Mapper.Sc.Configuration.SitecoreTypeConfiguration.ResolveItem(Object target, Database database)
 at Glass.Mapper.Sc.GlassHtml.MakeEditable[T](Expression`1 field, Expression`1 standardOutput, T model, Object parameters, Context context, Database database, TextWriter writer)

Here is the template

public partial interface IGlassBase{

    [SitecoreId]
    Guid Id{ get; }

    [SitecoreInfo(SitecoreInfoType.Language)]
    Language Language{ get; }

    [SitecoreInfo(SitecoreInfoType.Version)]
    int Version { get; }

    [SitecoreInfo(SitecoreInfoType.Url)]
    string Url { get; }
}

public abstract partial class GlassBase : IGlassBase{

    [SitecoreId]
    public virtual Guid Id{ get; private set;}

    [SitecoreInfo(SitecoreInfoType.Language)]
    public virtual Language Language{ get; private set; }

    [SitecoreInfo(SitecoreInfoType.Version)]
    public virtual int Version { get; private set; }

    [SitecoreInfo(SitecoreInfoType.Url)]
    public virtual string Url { get; private set; }
}

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 27 (11 by maintainers)

Most upvoted comments

Just wanted to share my experience with this error. In my case, I was using a base interface that had the following properties:

ID Id { get; set; }

Language Language { get; set; }

string Name { get; set; }

ID TemplateId { get; set; }

IEnumerable<ID> BaseTemplateIds { get; set; }

Item Item { get; set; }

I was relying mostly on auto-mapping throughout the project, but in a special case I needed to infer types. For a while it all worked fine, but then I started getting the error. My solution, which seems obvious now, was to be more explicit specifying my ID field with an attribute, like so:

[SitecoreId]
ID Id { get; set; }

With the ID properly mapped, the error went away.