I am trying to migrate Sitecore items from Sitecore 8.1 to Sitecore 10.1.2. During migration I have got an error as 'Item' does not contain a definition for 'GlassCast' and no accessible extension method 'GlassCast' Below is my code

public IMap GetMapItem()
     if (this.ContextItem.IsDerived(Templates.Map.ID))
         return this.ContextItem.GlassCast<IMap>();

     return null;

1 Answer 1


With the latest version of GlassMapper, GlassCast method is obsolete with lots of other things. One of the important updates is new contexts which include IMvcContext, IRequestContext, IWebFormsContext. If you want to cast the Item type to IMap. You cannot simply do it using the GlassCast method, You need to create an object of MVC Context (probably the one you will be working on the most), and then needs to code as below-

IMvcContext mvcContext = new MvcContext();
var mapItem= mvcContext.GetContextItem<IMap>();

The above code is for context item, for any other type of item you can use code as below -

IMvcContext mvcContext = new MvcContext();
var mapItem= mvcContext.SitecoreService.GetItem<IMap>(DataSourceItem);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.