Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GlassMapper v4 - InferType no longer working #132

Closed
AlexKasaku opened this issue May 6, 2015 · 13 comments
Closed

GlassMapper v4 - InferType no longer working #132

AlexKasaku opened this issue May 6, 2015 · 13 comments
Labels

Comments

@AlexKasaku
Copy link
Contributor

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.

@mikeedwards83
Copy link
Owner

Hi

Thanks for bring this to our attention. I have release update 4.0.1.5 to fix this issue. Please update your Nuget packages.

Mike

@AlexKasaku
Copy link
Contributor Author

Perfect! Appreciate the quick turn around!

@ssartell
Copy link

I may have just spent 4 or 5 hours trying to figure out how to get inferred types working on a new project before I stumbled onto this...

Thanks for the fix Mike!

@nbenninghoff
Copy link

Can anyone confirm if this is still working correctly in 4.2.1.190

@n-develop
Copy link

Sadly, I have a similar error when using 4.2.1.189. 😢

@ssartell
Copy link

ssartell commented Feb 2, 2017

@n-develop, I'm pretty sure this specific error has been resolved. My guess, if you're still having this problem, is that you're not registering the dll with your models with glass mapper.

@n-develop
Copy link

n-develop commented Feb 2, 2017

Could be true. I will check it tomorrow at work. Thank you for the tip, @ssartell.

@abhishekItengg
Copy link

I am using Glass Mapper version 4.4.0.199 and seems InferType is also not working there.

@Ubernt
Copy link

Ubernt commented Oct 1, 2018

I am using Glass Mapper version 4.4.0.199 and seems InferType is also not working there.

Same here. Any updates has this been fixed in later versions?

@cardinal252
Copy link

I have successfully used InferTypes in many versions of Glass in V4, have you loaded the types required in your GlassMapperScCustom using an AttributeConfigurationLoader?

@Ubernt
Copy link

Ubernt commented Oct 1, 2018

I have successfully used InferTypes in many versions of Glass in V4, have you loaded the types required in your GlassMapperScCustom using an AttributeConfigurationLoader?

Hello. Yes I have. I have supplied correct assembly name in AttributeConfigurationLoader.

We noticed that it randomly works. When site gets booted, or we do new publish locally, it stops or starts working again. I found out while debugging it takes sometimes correct interface type and sometimes that interface it inherits.

@cardinal252
Copy link

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

@Ubernt
Copy link

Ubernt commented 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants