Troubleshooting: Multitenancy¶
Common multitenancy issues and fixes across core, ASP.NET Core, and EF Core adapters.
TenantNotResolvedException¶
Symptoms
- Requests fail with "Tenant not resolved" or 400 ProblemDetails.
Fixes
- Ensure your host adapter populates
TenantResolutionContextbefore handlers run. - Verify
ResolutionOrderincludes the provider you expect (route/host/header/query/claim). - Check that your route parameter name, header names, or claim type match the incoming request.
TenantNotFoundException¶
Symptoms
- Requests fail even though a tenant ID is present.
Fixes
- Register
ITenantInfoStorewhen usingTenantValidationMode.Repository. - Register
ITenantInfoCachewhen usingTenantValidationMode.Cache. - Ensure the tenant exists in the store and is marked active.
Ambiguous tenant candidates¶
Symptoms
- Tenant resolves as null even though IDs are present.
Fixes
- Ensure headers/queries contain only a single tenant ID.
- Disable
RequireMatchAcrossSourcesor ensure all sources agree on the same ID. - Avoid sending multiple
X-Tenant-IDvalues separated by commas or semicolons.
Host-based resolution returns null¶
Symptoms
- Host provider does not resolve tenant for subdomains.
Fixes
- Ensure requests include a subdomain (for example,
tenant.app.com). - Configure
HostTenantSelectorto support custom host patterns. - Host provider ignores IP addresses and single-segment hosts.
Cache scope mismatch warnings¶
Symptoms
- Logs show "Cache scope tenant mismatch".
Fixes
- Install
CleanArchitecture.Extensions.Multitenancy.Cachingand callAddCleanArchitectureMultitenancyCachingafterAddCleanArchitectureCaching. - Ensure tenant resolution runs before caching behaviors.
Tenant context lost in background jobs¶
Symptoms
- Background workers execute without tenant context.
Fixes
- Serialize
TenantContextwithITenantContextSerializerand restore it in the worker. - Wrap work in
ITenantAccessor.BeginScopeto avoid AsyncLocal leakage.
EF Core: TenantSaveChangesInterceptor errors¶
Symptoms
- Writes throw
TenantNotResolvedExceptionor a tenant mismatch exception.
Fixes
- Ensure tenant context is set before SaveChanges executes.
- Verify
TenantIdPropertyNamematches your model configuration. - Confirm global entities are excluded with
IGlobalEntityor[GlobalEntity].
EF Core: database-per-tenant errors¶
Symptoms
TenantDbContextFactorythrows "Tenant connection string was not resolved".
Fixes
- Configure
ConnectionStringFormator register a customITenantConnectionResolver. - Ensure the current tenant is resolved before creating a DbContext.
- Use a relational EF Core provider (database-per-tenant requires relational).