Tag Archives: SitecoreContext throwing error after Sitecore upgrade

Sitecore Database broken after upgrade

Sitecore database broken after running Sitecore.UpdateApp 1.2

We followed Sitecore documentation for upgrading databases from 8.2 to 10.2. Steps you can find described here.

When we ran the Sitecore.UpdateApp tool, and try to open Sitecore Backend, we got following error:

[ArgumentNullException: The path "{E18F4BC6-46A2-4842-898B-B6613733F06F}" was not found.
[ArgumentNullException: The path "{E18F4BC6-46A2-4842-898B-B6613733F06F}" was not found.

After further research, this item is a /sitecore/layout/Devices item. It sounds that the database is incomplete, or broken.

I discovered that the upgraded solution includes a configuration patch file, which points to another \Data folder, hard-coded path to (C:\sites\local.sc.com\Data), which is not my local website\Data.

So Sitecore could not find the resources (now items as resources) and throws the error. I’ve commented the configuration file , and now it points to correct website\data folder and the issue is resolved.

GlassMapper update

Sitecore Upgrade to 10.2 – GlassMapper upgrade from 4 to 5

SitecoreContext

SitecoreContext is no longer available in GlassMapper 5+ and need to be replaced with MvcContext (used mainly in Controllers) or RequestContext (used outside Controllers).

So for every piece of code

private readonly ISitecoreContext _sitecoreContext

should be changed to

private readonly IRequestContext _sitecoreContext;

or

private readonly IMvcContext _sitecoreContext;

Note that GetItem method and etc need to be called from SitecoreService.

_sitecoreContext.GetItem<Item>("{8A1AC22A-EADC-46CE-9954-88BB2680AB83}")

should be changed to

_sitecoreContext.SitecoreService.GetItem<Item>("{8A1AC22A-EADC-46CE-9954-88BB2680AB83}")

Another example is where in the class method the SitecoreContext is initialized

For example

var context = new SitecoreContext();

need to be changed to

var context = new RequestContext(new SitecoreService(Sitecore.Context.Database)).SitecoreService;

GetHomeItem

_sitecoreContext.GetHomeItem<ISiteRoot>();

will be changed to

 context.SitecoreService.GetItem<ISiteRoot>(Sitecore.Context.Site.StartPath)

GlassView is obsolete

All views need to be updated as follow:

@inherits Glass.Mapper.Sc.Web.Mvc.GlassView<MyNamespace.MyViewModel>

 @Editable(Model, x => x.Item.Title)

to

@model MyNamespace.MyViewModel
@Html.Glass().Editable(Model, x => x.Item.Title)

GetCurrentItem

The new version GetCurrentItem is marked obsolete and replaced by GetContextItem method

 Item = _sitecoreContext.GetCurrentItem<MyModel>()

should be changed as follow, note that _sitecoreContext is now IMvcContext

 Item = _sitecoreContext.GetContextItem<MyModel>()