OrchardCMS/OrchardCore · error · ArgumentException

The specified tenant name is not valid.

Error message

The specified tenant name is not valid.

What it means

The IShellHost.GetSettings extension returns the ShellSettings for a tenant name, delegating to TryGetSettings. If no tenant (shell) with that name is registered, it throws ArgumentException 'The specified tenant name is not valid.' instead of returning null.

Solutions

  1. Use shellHost.TryGetSettings(tenant, out var settings) to handle missing tenants gracefully
  2. List valid tenants with shellHost.GetAllSettings() and match the exact Name
  3. Fix the tenant name string to match the configured tenant exactly
  4. Provision the tenant first if it genuinely should exist

Example fix

// before
var settings = shellHost.GetSettings("Defualt"); // typo -> ArgumentException
// after
if (!shellHost.TryGetSettings("Default", out var settings))
{
    // handle unknown tenant
}
Defensive patterns

Strategy: type-guard

Validate before calling

var knownTenants = shellHost.GetAllSettings().Select(s => s.Name, StringComparer.OrdinalIgnoreCase);
if (!knownTenants.Contains(tenant))
    throw new ArgumentException($"Unknown tenant '{tenant}'. Known: {string.Join(", ", knownTenants)}");

Type guard

bool TenantExists(IShellHost host, string tenant) => host.TryGetSettings(tenant, out _);

Try / catch

try { var settings = shellHost.GetSettings(tenant); }
catch (ArgumentException ex) when (ex.ParamName == nameof(tenant))
{ log.LogWarning("Tenant '{Tenant}' does not exist", tenant); }

Prevention

When it happens

Trigger: Calling shellHost.GetSettings(host, tenant) with a name that does not match any configured tenant, e.g. a typo ('default' vs 'Default' depending on registration), a deleted tenant, or a tenant not yet created in App_Data/tenants.json / tenants folder.

Common situations: Hard-coded tenant names drifting from actual tenants after renames; using a tenant URL prefix instead of its name; calling before tenant provisioning completes in setup or tests.

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/b77ffb8840228068. Report an issue: GitHub.

Appendix: source

Thrown at src/OrchardCore/OrchardCore.Abstractions/Shell/Extensions/ShellHostExtensions.cs:61

    /// Releases all shells so that new ones will be built for subsequent requests.
    /// Note: Can be used to free up resources after a given period of inactivity.
    /// </summary>
    public static async Task ReleaseAllShellContextsAsync(this IShellHost shellHost)
    {
        foreach (var settings in shellHost.GetAllSettings())
        {
            await shellHost.ReleaseShellContextAsync(settings);
        }
    }

    /// <summary>
    /// Retrieves the shell settings associated with the specified tenant.
    /// </summary>
    public static ShellSettings GetSettings(this IShellHost shellHost, string tenant)
    {
        if (!shellHost.TryGetSettings(tenant, out var settings))
        {
            throw new ArgumentException("The specified tenant name is not valid.", nameof(tenant));
        }

        return settings;
    }

    /// <summary>
    /// Whether or not a given tenant is in use in at least one active scope.
    /// </summary>
    public static bool IsShellActive(this IShellHost shellHost, ShellSettings settings) =>
        settings is { Name: not null } &&
        shellHost.TryGetShellContext(settings.Name, out var context) &&
        context.IsActive();
}

View on GitHub (pinned to 4306c0717f)