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

Model rendering error while using Glass.Mapper.sc.100 with Sitecore 10 #431

Open
Ashahi01 opened this issue Dec 20, 2020 · 8 comments
Open

Comments

@Ashahi01
Copy link

Ashahi01 commented Dec 20, 2020

We have upgraded our Sitecore application from 8.1 to 10.0 and with that upgrade, we also upgraded Glass mapper from Glass.Mapper.Sc.81 to Glass.Mapper.Sc.100 but when we run the website some of the pages gives us unhandled exception and we are clueless why this exceptions are being raised. The application was working fine when we were using Sitecore 8.1 with Glass.Mapper.Sc.81 and it broke when we upgraded the Sitecore version with glass mapper.
This is the exception that is raised in one of the page, other pages have similar exception but with different models.
The model item passed into the dictionary is of type 'Sitecore.Mvc.Presentation.RenderingModel', but this dictionary requires a model item of type 'HuronConsultingGroup.Common.Models.StaticImageCarousel'.
We verified our application and respective models if these models exist in the application and to look if things are fine and everything looked in place.
We are clueless why we are getting this exception, any help would be appreciated.

Model_rerendering_error.pdf

@Ashahi01 Ashahi01 changed the title Model rendering error while using Glass.Mapper.sc.100 with Sitecore 10 ( Error : The model item passed into the dictionary is of type 'Sitecore.Mvc.Presentation.RenderingModel', but this dictionary requires a model item of type 'HuronConsultingGroup.Common.Models.StaticImageCarousel'. ) Model rendering error while using Glass.Mapper.sc.100 with Sitecore 10 Dec 20, 2020
@mikeedwards83
Copy link
Owner

Can you show use the content of the <mvc.getModel> pipleine?

@Ashahi01
Copy link
Author

Ashahi01 commented Dec 21, 2020 via email

@mikeedwards83
Copy link
Owner

Arti

My message was from the github issue. so your response went to the github issue.

You will need to upload it somewhere and then add a link to the github issue.

@Ashahi01
Copy link
Author

Mike,

Please find the codes below :

  <mvc.getModel>
    <processor type="Glass.Mapper.Sc.Pipelines.Response.GetModel, Glass.Mapper.Sc.Mvc"
               patch:before="*[@type='Sitecore.Mvc.Pipelines.Response.GetModel.GetFromItem, Sitecore.Mvc']" />
    <processor type="Glass.Mapper.Sc.Pipelines.Response.GetModelFromView, Glass.Mapper.Sc.Mvc"
               patch:before="*[@type='Sitecore.Mvc.Pipelines.Response.GetModel.GetFromItem, Sitecore.Mvc']" />
  </mvc.getModel>

  <getChromeData>
    <processor type="Glass.Mapper.Sc.Pipelines.GetChromeData.EditFrameBuilder, Glass.Mapper.Sc" resolve="true"
               patch:before="processor[1]" />
  </getChromeData>

  <glassMapper.createResolver help="Processors should derive from Glass.Mapper.Sc.Pipelines.CreateResolver.CreateResolverProcessor">
    <!-- Add any changes to the standard resolver here. -->
  </glassMapper.createResolver>
  <glassMapper.getGlassLoaders help="Processors should derive from Glass.Mapper.Sc.Pipelines.GetGlassLoaders.GetGlassLoadersProcessor">
    <!-- Use this pipeline to add fluent configuration loaders. -->
    <!-- If you are using attribute configuration or automapping/on-demand mapping you don't need to do anything! -->
  </glassMapper.getGlassLoaders>
  <glassMapper.addMaps help="Processors should derive from Glass.Mapper.Sc.Pipelines.AddMaps.AddMapsProcessor">
    <!-- Add maps to the MapsConfigFactory here. -->
  </glassMapper.addMaps>
  <glassMapper.postLoad help="Processors should derive from Glass.Mapper.Sc.Pipelines.PostLoad.PostLoadProcessor" />
</pipelines>

@Ashahi01
Copy link
Author

Hi Mike,
All the pages which were broken are using View Rendering, We converted the view rendering to controller rendering and the page started working but doing so for whole application will be an overhead for us. If we think of applying the same approach, we will have to convert all our pages to use controller rendering. Is there any other way we can fix this issue.

@mikeedwards83
Copy link
Owner

Hi

I wanted to the see the final pipeline configuration for mvc.getModel as shown in /sitecore/admin/showconfig.aspx.

Could you copy it from that page an upload it to github?

Cheers

@Ashahi01
Copy link
Author

Ashahi01 commented Jan 4, 2021

Hi Mike,

Please find them below :
<mvc.getModel patch:source="Sitecore.Mvc.config"> <processor type="Glass.Mapper.Sc.Pipelines.Response.GetModel, Glass.Mapper.Sc.Mvc" patch:source="Glass.Mapper.Sc.config" /> <processor type="Glass.Mapper.Sc.Pipelines.Response.GetModelFromView, Glass.Mapper.Sc.Mvc" patch:source="Glass.Mapper.Sc.config" /> <processor type="Sitecore.Mvc.Pipelines.Response.GetModel.GetFromItem, Sitecore.Mvc" /> <processor type="Sitecore.Mvc.Pipelines.Response.GetModel.GetFromProperty, Sitecore.Mvc" /> <processor type="Sitecore.Mvc.Pipelines.Response.GetModel.GetFromLayout, Sitecore.Mvc" /> <processor type="Sitecore.Mvc.Pipelines.Response.GetModel.GetFromRenderingItem, Sitecore.Mvc" /> <processor type="Sitecore.Mvc.Pipelines.Response.GetModel.CreateDefaultRenderingModel, Sitecore.Mvc" /> <processor type="Sitecore.Mvc.Pipelines.Response.GetModel.InitializeModel, Sitecore.Mvc" /> </mvc.getModel>

@wene37
Copy link

wene37 commented Jun 22, 2022

Hi guys

I have the same problem after upgrading my solution from Sitecore 9.0.2 to Sitecore 10.2 and Glass Mapper to v5 for Sitecore 10.2. I found the problem and the solution for this:

In GetModelFromView there's a "new" check if model is assignable to a Sitecore RenderingModel. If so, then the model get not resolved and for this you get this error. To fix this, it should not check if current model is assignable from RenderingModel, but only if it's this exact type. Means the following code change:

Current line 67:
if (typeof(RenderingModel).IsAssignableFrom(modelType))
Replace with:
if (type == typeof (RenderingModel))

I did a custom implementation of GetModelFromView with this change and now everything works as before and expected. The cause of this is, that in every view rendering your models inherit Sitecore's RenderingModel and so non of them are resolved anymore.

Best regards,
Thomas

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

No branches or pull requests

3 participants