I'm using Sitecore 9.0 Update 2 with Glass Mapper.Sc version 5.2.13

I'm trying to create items in Sitecore using GlassMapper and the following code

repository.RequestContext.SitecoreService.CreateItem(parent, model);

But I get this error:

Type 'MyModel' does not have a Template ID or Branch ID.

MyModel is decorated with the [SitecoreType(TemplateId = "{my-model-template-guid}", AutoMap = true)] attribute and inherits from a base class that has a TemplateId property defined as

public virtual Guid TemplateId { get; set; }

but it does not have the '[SitecoreType(TemplateId = "{base-class-template-guid}", AutoMap = true)]' defined ... could be this the issue ? If I try creating items based on the base class model it works just fine.

All MyModel's properties are virtual but it seems to me the GlassMapper does not read the TemplateId specified as attribute.

Has anyone experienced this?

Update: Adding Model Classes:

Please see the model code below

[SitecoreType(TemplateId = "{AA1DE664-7E99-4ACB-8DB4-EBA8C3F0693E}", AutoMap = true)]
public class MyModel : GlassMapperBase
    [SitecoreField(FieldName = "First Name")]
    public virtual string FirstName { get; set; }

    [SitecoreField(FieldName = "Last Name")]
    public virtual string LastName { get; set; }

And the base class code together with the interface it implements:

public class GlassMapperBase : IGlassMapperBase
        public virtual Guid Id { get; set; }

        public virtual int Version { get; set; }

        public virtual Language Language { get; set; }

        public virtual string Name { get; set; }

        public virtual string ContentPath { get; set; }

        public virtual string FullPath { get; set; }

        public virtual string Url { get; set; }

        public virtual string DisplayName { get; set; }

        public virtual string TemplateName { get; set; }

        public virtual Guid TemplateId { get; set; }


public interface IGlassMapperBase
    Guid Id { get; set; }

    int Version { get; set; }

    Language Language { get; set; }

    string Name { get; set; }
  • Could you please add code snippets of your model classes to your question? Jan 16, 2019 at 13:48
  • 1
    Not sure why you are getting that error, but here is a suggestion. Just use the Sitecore API to create the item. Don't bother with Glass for that. It will be quicker to write and you won't get cryptic errors like this.
    – Richard Seal
    Jan 16, 2019 at 16:57


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.