GlassMapper v4 - InferType no longer working
See original GitHub issueHave 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:
- Created 8 years ago
- Comments:13 (2 by maintainers)
Top GitHub Comments
Wow, that was the case. Thank you so much for pointing this out!
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