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 ContentTypeServiceIf you're getting 'GetRootContent Resolution has 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 homepage = 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 ContextIf 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);