{"record":{"id":"f40d8a2f0ce8d14c","repo":"abpframework/abp","slug":"given-tenant-doesn-t-exist-0","errorCode":null,"errorMessage":"Given tenant doesn't exist: {0}","messagePattern":"Given tenant doesn't exist: (.+?)","errorType":"exception","errorClass":"UserFriendlyException","httpStatus":500,"severity":"error","filePath":"framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Pages/Abp/MultiTenancy/TenantSwitchModal.cshtml.cs","lineNumber":53,"sourceCode":"    {\n        Input = new TenantInfoModel();\n\n        if (CurrentTenant.IsAvailable)\n        {\n            var tenant = await TenantStore.FindAsync(CurrentTenant.GetId());\n            Input.Name = tenant?.Name;\n        }\n    }\n\n    public virtual async Task OnPostAsync()\n    {\n        Guid? tenantId = null;\n        if (!Input.Name.IsNullOrEmpty())\n        {\n            var tenant = await TenantStore.FindAsync(TenantNormalizer.NormalizeName(Input.Name!)!);\n            if (tenant == null)\n            {\n                throw new UserFriendlyException(L[\"GivenTenantIsNotExist\", Input.Name!]);\n            }\n\n            if (!tenant.IsActive)\n            {\n                throw new UserFriendlyException(L[\"GivenTenantIsNotAvailable\", Input.Name!]);\n            }\n\n            tenantId = tenant.Id;\n        }\n\n        AbpMultiTenancyCookieHelper.SetTenantCookie(HttpContext, tenantId, Options.TenantKey);\n    }\n\n    public class TenantInfoModel\n    {\n        [InputInfoText(\"SwitchTenantHint\")]\n        public string? Name { get; set; }\n    }","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/abpframework/abp/blob/7ed43b1931b9df46a50c0c59148a18645641d0df/framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Pages/Abp/MultiTenancy/TenantSwitchModal.cshtml.cs#L35-L71","documentation":"Thrown by TenantSwitchModal.OnPostAsync when the user submits a tenant name that, after normalization, is not found by ITenantStore.FindAsync. It surfaces a localized UserFriendlyException (key 'GivenTenantIsNotExist') so the UI can show a friendly message rather than a raw error. It only fires when Input.Name is non-empty.","triggerScenarios":"Posting the tenant-switch modal with a name that does not match any tenant in the store (after TenantNormalizer.NormalizeName), e.g. a typo, a deleted tenant, or a tenant in a different store/backend.","commonSituations":"User mistypes the tenant name; tenant was soft-deleted but the UI still offered it; multi-database tenant store pointing at the wrong DB; normalization rules (trim/casing) differ between save and lookup; switching tenants while not yet on the host database.","solutions":["Double-check the tenant name spelling against the tenants list in the management UI.","Confirm the tenant exists in the same ITenantStore backend the host is querying.","Verify TenantNormalizer configuration matches between creation and lookup (casing/trim rules).","If the tenant was deleted, restore it or stop referencing it."],"exampleFix":"// before: switching to 'Acme ' (trailing space) -> tenant not found\n// after: trim/normalize before submit, or pick from the validated tenant list\nvar normalized = TenantNormalizer.NormalizeName(inputName);\nvar tenant = await TenantStore.FindAsync(normalized);","handlingStrategy":"validation","validationCode":"var normalized = tenantNormalizer.NormalizeName(inputName);\nvar tenant = await tenantStore.FindAsync(normalized);\nif (tenant == null)\n{\n    // show friendly 'not found' instead of letting the modal throw\n}","typeGuard":"null","tryCatchPattern":"try { await OnPostAsync(); }\ncatch (UserFriendlyException ex) when (ex.Code == \"GivenTenantIsNotExist\")\n{ /* show localized error to user */ }","preventionTips":["Offer tenants from a validated dropdown rather than free-text entry.","Apply the same normalization on entry and lookup.","Confirm the ITenantStore points at the correct database.","Handle stale tenant references in cached UI lists."],"tags":["multitenancy","validation","abp","userfriendly"],"backgroundTag":null,"analyzedSha":"7ed43b1931b9df46a50c0c59148a18645641d0df","analyzedAt":"2026-08-13T16:26:11.351Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}