OrchardCMS/OrchardCore · error · InvalidOperationException

Could not find a resource of type

Error message

Could not find a resource of type '{settings.Type}' named '{settings.Name}' with version '{settings.Version ?? "any"}'.

What it means

ResourceManager.DoGetRequiredResources resolves every resource declared via RequireSettings (required resources for a page) and throws this InvalidOperationException when a manifest lookup by type/name/version finds no matching registered ResourceDefinition. It means the page requested a resource that no module registered, or the requested version does not exist.

Solutions

  1. Correct the resource name/type in the code or settings requesting it, matching the name declared in the module's ResourceManifest.
  2. Check that the module or feature which registers the resource is enabled.
  3. If a version is specified in the RequireSettings, remove it or set it to one that exists; 'any' matches the latest registered version.
  4. Use ResourceManager/ResourceManagementOptions to list registered resources of that type to see valid names and versions.

Example fix

// before
builder.RequireSettings.Add(new RequireSettings { Type = "script", Name = "jQuery-ui", Version = "1.12" });
// after
builder.RequireSettings.Add(new RequireSettings { Type = "script", Name = "jQuery-ui" }); // existing registered name, no strict version
Defensive patterns

Strategy: validation

Validate before calling

var registered = resourceManager.GetResources(resourceType); // or inspect manifests
if (!registered.Any(r => r.Name == settings.Name && (settings.Version is null || r.GetVersion(settings.Version) != null)))
    throw new InvalidOperationException($"Resource '{resourceType}/{settings.Name}' v'{settings.Version ?? "any"}' is not registered.");

Type guard

bool IsResourceRegistered(IEnumerable<ResourceDefinition> defs, RequireSettings s) =>
    defs.Any(d => d.Name == s.Name && (s.Version is null || System.Version.TryParse(s.Version, out _) == false || d.Version == s.Version));

Try / catch

try
{
    var contexts = resourceManager.GetRequiredResources(resourceType);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("Could not find a resource of type"))
{
    logger.LogWarning(ex, "Missing resource; skipping render.");
}

Prevention

When it happens

Trigger: Calling GetRequiredResources, styleSheets, headScripts, footScripts, localScripts or localStyles after RequireSettings entries were added (e.g. via RequireSettings or ResourceManifest) whose type/name/version combination matches no registered resource, or whose version does not match the registered one.

Common situations: Typo in the resource name in a theme/module or recipe; module that registered the resource (its ResourceManifest) is disabled; hardcoded version string that no longer matches after a dependency upgrade; required resource declared in placement or theme settings pointing at a removed resource.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13). Data as JSON: /api/errors/7372a82f514d8b44. Report an issue: GitHub.

Appendix: source

Thrown at src/OrchardCore/OrchardCore.ResourceManagement/ResourceManager.cs:323

    {
        return _styles ?? EmptyList<IHtmlContent>.Instance;
    }

    public IEnumerable<ResourceRequiredContext> GetRequiredResources(string resourceType)
        => DoGetRequiredResources(resourceType);

    private ResourceRequiredContext[] DoGetRequiredResources(string resourceType)
    {
        if (_builtResources.TryGetValue(resourceType, out var requiredResources) && requiredResources != null)
        {
            return requiredResources;
        }

        var allResources = new ResourceDictionary();
        foreach (var settings in ResolveRequiredResources(resourceType))
        {
            var resource = FindResource(settings)
                ?? throw new InvalidOperationException($"Could not find a resource of type '{settings.Type}' named '{settings.Name}' with version '{settings.Version ?? "any"}'.");

            ExpandDependencies(resource, settings, allResources);
        }

        requiredResources = new ResourceRequiredContext[allResources.Count];
        int i, first = 0, byDependency = allResources.FirstCount, last = allResources.Count - allResources.LastCount;
        foreach (DictionaryEntry entry in allResources)
        {
            var settings = (RequireSettings)entry.Value;
            if (settings.Position == ResourcePosition.First)
            {
                i = first++;
            }
            else if (settings.Position == ResourcePosition.Last)
            {
                i = last++;
            }
            else

View on GitHub (pinned to 4306c0717f)