In this tutorial, you will learn how to fix the GetRootContent Resolution is not frozen
error. If you run into this error, it's highly likely that you're trying to either use one of the Umbraco APIs within a custom application event handler or, some custom code is trying to process in a vanilla MCS controller. When you encounter this error it signifies, that the Umbraco context hasn't been fully initialised yet. YOu are trying to access something before it is ready. So how do we fix it?
The Umbraco Helper Vs The ContentTypeService
If you are encountering a 'GetRootContent Resolution has not frozen` error, one solution is to change the way you are trying to query data from Umbraco. If you want to talk to Umbraco within a controller, or, a view, the recommended approach is to you should use the Umbraco Helper. The code to access it looks like this:
The Umbraco Helper is the main tool in your toolbox for accessing Umbraco related stuff. Using UmbracoHelper
you can do tasks like accessing the homepage in code:
One thing that UmbracoHelper
needs to work as expected is the HttpContext
. For example, in an event handler, you may not have a HttpContext
. If you do not have a page context, an alternative approach to query Umbraco for data is to use the ContentService
and the ContentTypeService
. You can do this using this code:
Using ContentService
if you want to get a reference to the root node, you could use this snippet:
If you get a 'GetRootContent Resolution is not frozen' error it is likely that you're trying to use the wrong API for the job. Try using ContentService
instead!
I Really Want To Use The Umbraco Context
If you really want to try and use the UmbracoHelper
and you can't use the ApplicationContext for whatever reason, you could always try to manually create the Umbraco context yourself. This approach will work on Umbraco v7.3 upwards:
The snippet below can be used on Umbraco v7.2 and below:
If you bump into this exception, changing your code and experimenting with one of the two approaches listed above should fix the error. Alternatively, if you encounter this error, trying to change your architecture to make your call slightly later in the pipeline should fix it! Happy Coding 🤘