abpframework/abp · error · UserFriendlyException

Given tenant doesn't exist: {0}

Error message

Given tenant doesn't exist: {0}

What it means

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.

Source

Thrown at framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Pages/Abp/MultiTenancy/TenantSwitchModal.cshtml.cs:53

    {
        Input = new TenantInfoModel();

        if (CurrentTenant.IsAvailable)
        {
            var tenant = await TenantStore.FindAsync(CurrentTenant.GetId());
            Input.Name = tenant?.Name;
        }
    }

    public virtual async Task OnPostAsync()
    {
        Guid? tenantId = null;
        if (!Input.Name.IsNullOrEmpty())
        {
            var tenant = await TenantStore.FindAsync(TenantNormalizer.NormalizeName(Input.Name!)!);
            if (tenant == null)
            {
                throw new UserFriendlyException(L["GivenTenantIsNotExist", Input.Name!]);
            }

            if (!tenant.IsActive)
            {
                throw new UserFriendlyException(L["GivenTenantIsNotAvailable", Input.Name!]);
            }

            tenantId = tenant.Id;
        }

        AbpMultiTenancyCookieHelper.SetTenantCookie(HttpContext, tenantId, Options.TenantKey);
    }

    public class TenantInfoModel
    {
        [InputInfoText("SwitchTenantHint")]
        public string? Name { get; set; }
    }

View on GitHub (pinned to 7ed43b1931)

Solutions

  1. Double-check the tenant name spelling against the tenants list in the management UI.
  2. Confirm the tenant exists in the same ITenantStore backend the host is querying.
  3. Verify TenantNormalizer configuration matches between creation and lookup (casing/trim rules).
  4. If the tenant was deleted, restore it or stop referencing it.

Example fix

// before: switching to 'Acme ' (trailing space) -> tenant not found
// after: trim/normalize before submit, or pick from the validated tenant list
var normalized = TenantNormalizer.NormalizeName(inputName);
var tenant = await TenantStore.FindAsync(normalized);
Defensive patterns

Strategy: validation

Validate before calling

var normalized = tenantNormalizer.NormalizeName(inputName);
var tenant = await tenantStore.FindAsync(normalized);
if (tenant == null)
{
    // show friendly 'not found' instead of letting the modal throw
}

Type guard

null

Try / catch

try { await OnPostAsync(); }
catch (UserFriendlyException ex) when (ex.Code == "GivenTenantIsNotExist")
{ /* show localized error to user */ }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of abpframework/abp@7ed43b1931 (2026-08-13). Data as JSON: /api/errors/f40d8a2f0ce8d14c. Report an issue: GitHub.