Sebastian Pierre
09/17/2024, 10:32 AM'((Umbraco.Cms.Web.Common.PublishedModels.StartPage)root2).CompanyContainerMappingsInternal' threw an exception of type 'System.ArgumentNullException'
.
So for some reason I cannot access Umbraco propertly in the jobs. I've tried looking at @Sebastiaan's [blogpost](https://cultiv.nl/blog/using-hangfire-to-update-umbraco-content/) about it but it did not seem to work either.
https://cdn.discordapp.com/attachments/1285548823573168201/1285548824454103071/image.png?ex=66eaac24&is=66e95aa4&hm=1695d295ae360e54e076b832aae765f65827771880a5afe7959926b524315af7&Sebastian Pierre
09/17/2024, 10:33 AMdawoe21
09/17/2024, 10:38 AMSebastian Pierre
09/17/2024, 10:40 AMSebastian Pierre
09/17/2024, 10:49 AMJemayn
09/17/2024, 11:00 AMcsharp
var rootNode = _.UmbracoContext.Content?.GetAtRoot().FirstOrDefault();
Atleast we have several hangfire jobs where we access the content cache and can get properties using an approach like this:
csharp
using var context = _umbracoContextFactory.EnsureUmbracoContext();
var archive = context
.UmbracoContext.Content?.GetAtRoot()
.FirstOrDefault();
Sebastian Pierre
09/17/2024, 11:11 AMSebastian Pierre
09/17/2024, 11:16 AMSebastian Pierre
09/17/2024, 11:19 AMSander L
09/17/2024, 11:19 AMSebastian Pierre
09/17/2024, 11:20 AMSander L
09/17/2024, 11:21 AMpublic string Example(string culture)
{
_variationContextAccessor.VariationContext = new VariationContext(culture);
var context = _umbracoContextFactory.EnsureUmbracoContext();
var home = context.UmbracoContext.Content?.GetAtRoot().FirstOrDefault();
var homeId = home?.Id ?? -1;
return $"Task ran with culture: {culture}. Found Home node id: {homeId}. Ran on machine: {Environment.MachineName}";
}
is an example task we madeSebastian Pierre
09/17/2024, 11:22 AMSebastian Pierre
09/17/2024, 11:32 AMSander L
09/17/2024, 11:32 AM