dotnet/aspnetcore · error · InvalidOperationException
The provider was not found in the providers list of the give
Error message
The provider was not found in the providers list of the given section ID '{identifier}'. What it means
Thrown by SectionRegistry.RemoveProvider when the identifier key exists in _providersByIdentifier but the specific SectionContent instance was not found in its list (List.LastIndexOf returned -1). It indicates a provider that the caller believes is registered was never added to that identifier's list, or was added under a different identifier.
Source
Thrown at src/Components/Components/src/Sections/SectionRegistry.cs:46
}
else
{
providers.Add(provider);
}
}
public void RemoveProvider(object identifier, SectionContent provider)
{
if (!_providersByIdentifier.TryGetValue(identifier, out var providers))
{
throw new InvalidOperationException($"There are no content providers with the given section ID '{identifier}'.");
}
var index = providers.LastIndexOf(provider);
if (index < 0)
{
throw new InvalidOperationException($"The provider was not found in the providers list of the given section ID '{identifier}'.");
}
providers.RemoveAt(index);
if (index == providers.Count)
{
// We just removed the most recently added provider, meaning we need to change
// the current content to that of second most recently added provider.
var contentProvider = GetCurrentProviderContentOrDefault(providers);
NotifyContentChangedForSubscriber(identifier, contentProvider);
if (_subscribersByIdentifier.TryGetValue(identifier, out var subscriber))
{
DetectRenderModeMismatch(identifier, subscriber, contentProvider);
}
}
}
View on GitHub (pinned to 3600ca084e)
Solutions
- When changing both SectionId and IsDefaultContent on the same SectionContent, change them in the same parameter update so SetParametersAsync re-registers atomically (SectionContent.cs:71 already checks both — make sure your usage does too).
- Do not share one SectionContent instance across two registries or two identifiers; each instance belongs to exactly one identifier at a time.
- Audit any custom code that calls SectionRegistry.RemoveProvider directly to confirm it always passes the identifier the provider was Add'd with.
- Reproduce under a debugger with a breakpoint on the throw and inspect _providersByIdentifier[identifier] to see which provider objects are actually listed.
Example fix
// before: identifier swap with mismatched add/remove <SectionContent SectionId="@oldId" /> @* later *@ <SectionContent SectionId="@newId" /> // if instance identity reused, RemoveProvider may miss // after: let Blazor recreate the component with a @key so Add/Remove pair cleanly <SectionContent SectionId="@id" @key="id" />
Defensive patterns
Strategy: validation
Validate before calling
// In a unit test exercising a custom host, assert Add/Remove pairing symmetry: // var added = new HashSet<SectionContent>(); // registry.OnAdd = (id, p) => added.Add(p); // registry.OnRemove = (id, p) => Assert.Contains(p, added); // In app code, simply ensure SectionContent is never reused across identifiers without re-instantiation.
Prevention
- Use @key on SectionContent bound to the identifier so a change in identifier recreates the instance instead of repointing it.
- Do not mutate IsDefaultContent and SectionId independently across renders; change them together in one SetParametersAsync.
- Audit any code that holds a SectionContent reference outside the renderer.
When it happens
Trigger: SectionContent.Dispose or SetParametersAsync invokes _registry.RemoveProvider(identifier, this); the identifier is registered but 'this' is not a member of its provider list. Happens when the same SectionContent instance is registered under one identifier and removed under another, when the registry's list was mutated out of band, or when IsDefaultContent flipping caused AddProvider under one path but RemoveProvider under another.
Common situations: A SectionContent that swaps SectionId at runtime and the AddProvider/RemoveProvider pair gets out of step because IsDefaultContent also changed (the condition at SectionContent.cs:71 must include IsDefaultContent to re-pair correctly); custom test doubles that drive the registry directly; race during prerendering where the prerendered instance and the interactive instance both attempt removal.
Related errors
- There are no content providers with the given section ID '{i
- The subscriber with the given section ID '{identifier}' is a
- There is already a subscriber to the content with the given
- Services cannot be accessed before the component is initiali
- There is no file with ID ${fileId}. The file list may have c
AI-assisted analysis of dotnet/aspnetcore@3600ca084e (2026-08-11).
Data as JSON: /api/errors/54cce7d8e3f50b82.
Report an issue: GitHub.