question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GlassMapper v4 - InferType no longer working

See original GitHub issue

Have just upgraded a solution to GlassMapper v4 and am having some trouble with a page that uses inferred types (other pages seem to be working fine).

In the solution we have the following model:

[SitecoreType(TemplateId = TemplateIds.ElementCardDeck, AutoMap = true)]
public interface IElementCardDeck : IBaseElement
{
   [SitecoreChildren(InferType = true)]
   IEnumerable<IBaseElementCard> Cards { get; set; }
}

There are various other templates that inherit from IBaseElementCard, not shown.

This was previously working in v3, though required the configuration to be preloaded (as described here):

public static IConfigurationLoader[] GlassLoaders()
{
   var attributes = new AttributeConfigurationLoader("Project.Glass.Models");

   return new IConfigurationLoader[] { attributes };
}

As part of the upgrade to v4, I ensured that this loader code was ported across. However, it does not seem to be having an effect and we are now getting the error we previously got in v3 before applying this fix:

The model item passed into the dictionary is of type ‘Castle.Proxies.IBaseElementCardProxy’, but this dictionary requires a model item of type ‘Project.Glass.Models.IElementCardContent’.

IElementCardContent is one of the derived types.

Any ideas? Have I missed something obvious in the upgrade? I’ve stepped through the solution and the GlassLoaders() method is definitely getting called.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Uberntcommented, Oct 1, 2018

I used to see that behaviour when Glass couldn’t figure out the correct type - often where 2 different types had the same template id

Wow, that was the case. Thank you so much for pointing this out!

0reactions
cardinal252commented, Oct 1, 2018

I used to see that behaviour when Glass couldn’t figure out the correct type - often where 2 different types had the same template id

Read more comments on GitHub >

github_iconTop Results From Across the Web

Glass Mapper v4 InferType Cast issue
My hack around solution was to specify the subtypes as properties like you did with AAACh and BBBch. But setting up without lazy...
Read more >
Trouble with Glass.Mapper InferType property
This code does not work as it is and when I debug it, the type returned is of the base class instead of...
Read more >
Glass.Mapper Part 2 of 2 – What is New and Changed in ...
In the previous post we talked about What Glass Mapper is and How to Use it. In this post I will talk about...
Read more >
Documentation
In V5 we have had to remove the powershell script support because it is no longer supported in Nuget v3. Instead we now...
Read more >
GlassMapper upgrade from 4 to 5 - Gerhart Magdás
GlassMapper was removed from 5.x SitecoreContext. This means in the solution, you will need to replace all of the SitecoreContext references ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found