1

We are upgrading Sitecore to 9.3 and glass mapper to Glass.Mapper.Sc.93 (v5.6.158-alpha). Having an issue with most of our Glass.Mapper.Sc.Fields.Link types coming back as null. which used to work fine in v4. I am a total noob to glass btw.

Here is the error: Databases are identical except of course one has been upgraded to sc 9.3. Taking it from the top: enter image description here

Secondary navigation calls Model.SearchPage which is coming back as null when using Glass V5

enter image description here enter image description here

In Glass V4 it works just fine and is not null:

enter image description here

Not sure if relevant but here is the mapping (identical in V4 and V5):

enter image description here

Here is the calling code that works in v4. retItem.SearchPage is populated and not null:

enter image description here

Here is the v5 code (I realize the ISitecoreContext is marked obsolete in v5, so I tried the following approaches to get the item in V5). All items have their .SearchPage property returned as null: enter image description here

1
  • Can you please add screenshot of model in both v4 and v5 which has SearchPage? Commented Jan 24, 2020 at 3:07

1 Answer 1

3

In order to use these new services, you have to first inject them with the Sitecore dependency injection container. Maybe that is the reason why you always get null results.

There is a good blog post about it: https://www.coreysmith.co/glass-mapper-5-dependency-injection/

Also, I have written my simple solution if you are using Helix: https://passionatesitecore.blogspot.com/

So simply first inject:

  serviceCollection.AddScoped<ISitecoreService>(sp => new SitecoreService(Sitecore.Context.Database));

Then get the service:

public ISitecoreService GetSitecoreService() => Sitecore.DependencyInjection.ServiceLocator.ServiceProvider.GetService<ISitecoreService>();

then use this service to map items:

var mappedItem = GetSitecoreService().GetItem<ClassModel>(Item);

Your Answer

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

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