Crosspost: https://orchard.codeplex.com/discussions/471475
Sometimes, I get this error: "Instances cannot be resolved and nested lifetimes cannot be created from this LifetimeScope as it has already been disposed." when querying some Content Items.
This is my function that builds the items:
protected IEnumerable<ContentItem> GetResources(string[] productFilters, string[] topicFilters, string[] techLevelFilters)
{
var cacheKey = BuildCacheKey(productFilters, topicFilters, techLevelFilters);
var resourceItems = ContentManager.Query().ForType("Resource").ForVersion(VersionOptions.Published).List();
if (productFilters != null && productFilters.Any())
{
resourceItems = resourceItems.Where(r => productFilters.Contains(GetTaxonomyFieldValue(r, productTaxonomy)));
}
if (topicFilters != null && topicFilters.Any())
{
resourceItems = resourceItems.Where(r => topicFilters.Contains(GetTaxonomyFieldValue(r, topicTaxonomy)));
}
if (techLevelFilters != null && techLevelFilters.Any())
{
resourceItems = resourceItems.Where(r => techLevelFilters.Contains(GetTaxonomyFieldValue(r, techLevelTaxonomy)));
}
return _cacheManager.Get(cacheKey, ctx =>
{
ctx.Monitor(_clock.When(TimeSpan.FromMinutes(CacheTime)));
return resourceItems;
});
}
This is part of the function that calls the one above, which at times shows the error:
string[] newProductFilters = GetProductFilters(0);
if (newProductFilters != null && newProductFilters.Any())
{
productFilters = productFilters.Concat(newProductFilters).ToArray();
}
var resourceItems = GetResources(productFilters, topicFilters, techLevelFilters);
It happens sporadically and I can't really find a cause of the issue. Any piece of advise or information would be highly appreciated. Thanks!