is to create a Scope if you are unsure of whether one exists or not...
Inside this Scope using statement, you'll either have access to a Transient Scope, either 'nested' or a new one will be created. THEN you can can call EnsureUmbracoContext, to get reference to the UmbracoContext on that Scope/Thread... whereas in your example you are doing that 'before' creating the scope!
eg
public IPublishedContent GetActivityNodePublished(int activityId)
{
var nodeId = GetActivityNodeId(activityId);
using (var scope = _scopeProvider.CreateScope(autoComplete: true))
{
using (UmbracoContextReference context = contextFactory.EnsureUmbracoContext())
{
var result = context.UmbracoContext.Content.GetById(nodeId);
return result;
}
}
}
Thanks for your reply.
I've been breaking my head over this, but I've found it: somewhere a URL was taken in code to get an URL via DI (other things where also injected into that class via DI).
This caused errors all over the place in the entire project. Once it was changed back to
EnsureUmbracoContext gives me a disposed UmbracoContext (from event)
Hi,
I've been breaking my head on this for some time now: From UI-O-Matic, we're firing an event on save, then we call a service to get the corresponding Umbraco-node. Because this is a background-thing, I get that there's no default UmbracoContext. I've read up on this topic: https://our.umbraco.com/forum/using-umbraco-and-getting-started/102676-triggering-index-rebuild-via-hangfire-causes-objectdisposedexception-in-nucache#comment-321129 and updated Umbraco to 8.16.
But no matter what I try, it's always disposed: Code calling the function:
private void UIOMaticObjectService_UpdatedObject(object sender, UIOMatic.ObjectEventArgs e) { if (e.ObjectType.Name == "ActivitiesSchema") { var activitySchema = (ActivitiesSchema)e.Object;
Function:
Can anybody help me out here?
Hi Sibren
Have you tried creating your Scope, before grabbing hold of your UmbracoContext...?
The suggestion in the post:
https://our.umbraco.com/forum/using-umbraco-and-getting-started/102676-triggering-index-rebuild-via-hangfire-causes-objectdisposedexception-in-nucache#comment-321129
is to create a Scope if you are unsure of whether one exists or not...
Inside this Scope using statement, you'll either have access to a Transient Scope, either 'nested' or a new one will be created. THEN you can can call EnsureUmbracoContext, to get reference to the UmbracoContext on that Scope/Thread... whereas in your example you are doing that 'before' creating the scope!
eg
regards
Marc
Hi Marc,
Thanks for your reply. I've been breaking my head over this, but I've found it: somewhere a URL was taken in code to get an URL via DI (other things where also injected into that class via DI). This caused errors all over the place in the entire project. Once it was changed back to
All issues magically disappeared.
is working on a reply...