Umbraco : GetRootContent Resolution is not frozen, it is not yet possible to get values from it

If you run into this error, then it’s likely that you’re trying to do some form of Umbraco API call in application event handler, or, in some custom code outside of the normal route hi-jacking path. The error basically means the Umbraco context hasn’t got far enough into the pipeline to set everything up. In today’s tutorial, I’m going to cover some potential resolutions to fix this error.

The Umbraco Helper Vs The ContentTypeService

If you’re getting ‘GetRootContent Resolution is not frozen’ it is likely you’re using the wrong API. If you want to talk to Umbraco within a controller, or, a view, then you should use the Umbraco Helper, which looks like this:

var context = UmbracoContext.Current;
var helper = new UmbracoHelper(context);

The Umbraco Helper is the API you should look at when you want to access other Umbraco stuff within a page, you can do things get the homepage etc…

var helper = new UmbracoHelper();
var hompeage = helper.TypedContentAtRoot();

If you’re trying to access Umbraco and you’re not in a page context, you should look at ‘ContentService’ and ‘ContentTypeService’, you can get access to the API using:

var contentService = ApplicationContext.Current.Services.ContentService;
var contentTypeService = ApplicationContext.Current.Services.ContentTypeService;

So if you want to get a reference to the homepage, for example, you could use this snippet:

ApplicationContext.Current.Services.ContentService.GetRootContent()

So hopefully, you should see that if you get something like ‘GetRootContent Resolution is not frozen’ it is likely that you’re trying to use the wrong API for the job.

I Really Want To Use The Umbraco Context

If you really want to try and use the Umbraco Context with the Umbraco helper for instance within Custom HttpHandler and you can’t use the ApplicationContext for whatever reason, you could always try to manually create the Umbraco context.

Umbraco 7.3 Upwards

using System.IO;
using System.Web;
using System.Web.Hosting;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Web;
using Umbraco.Web.Routing;
using Umbraco.Web.Security;
var context = new HttpContextWrapper(new HttpContext(new SimpleWorkerRequest(/, string.Empty, new StringWriter())));
UmbracoContext.EnsureContext(
context,
ApplicationContext.Current,
new WebSecurity(context, ApplicationContext.Current),
UmbracoConfig.For.UmbracoSettings(),
UrlProviderResolver.Current.Providers,
false);

Umbraco 7.2 Downwards

var context = new HttpContextWrapper(new HttpContext(new SimpleWorkerRequest(/, string.Empty, new StringWriter())));
UmbracoContext.EnsureContext(
context,
ApplicationContext.Current,
new WebSecurity(context, ApplicationContext.Current),
true);

Jon D Jones

Software Architect, Programmer and Technologist Jon Jones is founder and CEO of London-based tech firm Digital Prompt. He has been working in the field for nearly a decade, specializing in new technologies and technical solution research in the web business. A passionate blogger by heart , speaker & consultant from England.. always on the hunt for the next challenge

More Posts

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *