{"record":{"id":"b77ffb8840228068","repo":"OrchardCMS/OrchardCore","slug":"the-specified-tenant-name-is-not-valid","errorCode":null,"errorMessage":"The specified tenant name is not valid.","messagePattern":"The specified tenant name is not valid\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.Abstractions/Shell/Extensions/ShellHostExtensions.cs","lineNumber":61,"sourceCode":"    /// Releases all shells so that new ones will be built for subsequent requests.\n    /// Note: Can be used to free up resources after a given period of inactivity.\n    /// </summary>\n    public static async Task ReleaseAllShellContextsAsync(this IShellHost shellHost)\n    {\n        foreach (var settings in shellHost.GetAllSettings())\n        {\n            await shellHost.ReleaseShellContextAsync(settings);\n        }\n    }\n\n    /// <summary>\n    /// Retrieves the shell settings associated with the specified tenant.\n    /// </summary>\n    public static ShellSettings GetSettings(this IShellHost shellHost, string tenant)\n    {\n        if (!shellHost.TryGetSettings(tenant, out var settings))\n        {\n            throw new ArgumentException(\"The specified tenant name is not valid.\", nameof(tenant));\n        }\n\n        return settings;\n    }\n\n    /// <summary>\n    /// Whether or not a given tenant is in use in at least one active scope.\n    /// </summary>\n    public static bool IsShellActive(this IShellHost shellHost, ShellSettings settings) =>\n        settings is { Name: not null } &&\n        shellHost.TryGetShellContext(settings.Name, out var context) &&\n        context.IsActive();\n}\n","sourceCodeStart":43,"sourceCodeEnd":75,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.Abstractions/Shell/Extensions/ShellHostExtensions.cs#L43-L75","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use shellHost.TryGetSettings(tenant, out var settings) to handle missing tenants gracefully","List valid tenants with shellHost.GetAllSettings() and match the exact Name","Fix the tenant name string to match the configured tenant exactly","Provision the tenant first if it genuinely should exist"],"exampleFix":"// before\nvar settings = shellHost.GetSettings(\"Defualt\"); // typo -> ArgumentException\n// after\nif (!shellHost.TryGetSettings(\"Default\", out var settings))\n{\n    // handle unknown tenant\n}","handlingStrategy":"type-guard","validationCode":"var knownTenants = shellHost.GetAllSettings().Select(s => s.Name, StringComparer.OrdinalIgnoreCase);\nif (!knownTenants.Contains(tenant))\n    throw new ArgumentException($\"Unknown tenant '{tenant}'. Known: {string.Join(\", \", knownTenants)}\");","typeGuard":"bool TenantExists(IShellHost host, string tenant) => host.TryGetSettings(tenant, out _);","tryCatchPattern":"try { var settings = shellHost.GetSettings(tenant); }\ncatch (ArgumentException ex) when (ex.ParamName == nameof(tenant))\n{ log.LogWarning(\"Tenant '{Tenant}' does not exist\", tenant); }","preventionTips":["Prefer TryGetSettings over GetSettings when a tenant may be absent","Discover tenant names at runtime via GetAllSettings() instead of hard-coding","Verify the tenant is provisioned before referencing it","Don't confuse tenant URL prefixes with tenant names"],"tags":["tenants","shell","argument"],"backgroundTag":"resource-not-found","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}