{"record":{"id":"f2cc0e5f33e3c59f","repo":"OrchardCMS/OrchardCore","slug":"the-default-tenant-can-t-be-removed","errorCode":null,"errorMessage":"The 'Default' tenant can't be removed.","messagePattern":"The 'Default' tenant can't be removed\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore/Shell/ShellHost.cs","lineNumber":517,"sourceCode":"        shellSettings.IsRunning() ||\n        shellSettings.IsUninitialized() ||\n        shellSettings.IsInitializing();\n\n    /// <summary>\n    /// Whether or not a shell can be released and removed from the list, false if disabled and still in use.\n    /// Note: A disabled shell still in use will be released by its last scope, and keeping it in the list\n    /// prevents a consumer from creating a new one that would have a null service provider.\n    /// </summary>\n    private bool CanReleaseShell(ShellSettings settings) => !settings.IsDisabled() || !IsShellActive(settings);\n\n    /// <summary>\n    /// Checks if a shell can be removed, throws an exception if the shell is neither uninitialized nor disabled.\n    /// </summary>\n    private void CheckCanRemoveShell(ShellSettings settings)\n    {\n        if (settings.IsDefaultShell())\n        {\n            throw new InvalidOperationException($\"The '{ShellSettings.DefaultShellName}' tenant can't be removed.\");\n        }\n\n        // A disabled shell may be still in use in at least one active scope.\n        if (!settings.IsRemovable() || IsShellActive(settings))\n        {\n            throw new InvalidOperationException(\n                $\"The tenant '{settings.Name}' can't be removed as it is neither uninitialized nor disabled.\");\n        }\n    }\n\n    /// <summary>\n    /// Whether or not a shell is in use in at least one active scope.\n    /// </summary>\n    private bool IsShellActive(ShellSettings settings) =>\n        settings is { Name: not null } &&\n        _shellContexts.TryGetValue(settings.Name, out var context) &&\n        context.IsActive();\n","sourceCodeStart":499,"sourceCodeEnd":535,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore/Shell/ShellHost.cs#L499-L535","documentation":"CheckCanRemoveShell throws InvalidOperationException because the Default tenant is the root shell of an Orchard Core application and can never be removed. The check runs before RemoveShellSettingsAsync/RemoveShellContextAsync perform any deletion.","triggerScenarios":"Calling RemoveShellSettingsAsync or RemoveShellContextAsync with the settings of the 'Default' tenant (ShellSettings.DefaultShellName).","commonSituations":"Bulk tenant-cleanup scripts that iterate all tenants without excluding Default; admin UI/logic bugs passing the wrong tenant; recipes or migrations attempting to delete the Default tenant.","solutions":["Exclude the Default tenant before calling the remove APIs (check settings.IsDefaultShell() or settings.Name == \"Default\").","If the goal is to reset Default, disable/reconfigure it instead of removing it.","Fix the caller to pass the correct ShellSettings instance."],"exampleFix":"// before\nawait _shellHost.RemoveShellSettingsAsync(settings);\n// after\nif (!settings.IsDefaultShell())\n{\n    await _shellHost.RemoveShellSettingsAsync(settings);\n}","handlingStrategy":"validation","validationCode":"if (settings.IsDefaultShell() || settings.Name == ShellSettings.DefaultShellName)\n{\n    throw new InvalidOperationException(\"The Default tenant cannot be removed.\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always exclude the 'Default' tenant from delete loops and cleanup jobs.","Use settings.IsDefaultShell() as a precondition check before any removal call."],"tags":["multi-tenancy","tenants","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}