dotnet/aspnetcore · error · InvalidOperationException
Unable to find the provided template '{template}'
Error message
Unable to find the provided template '{template}' What it means
RouteTableFactory.GetEntry looks up a previously-parsed route template by its raw text among the templates derived from assembly scanning. If the requested template string does not case-insensitively equal any parsed template's RawText, the lookup fails and the factory throws InvalidOperationException. This indicates the caller asked for a template that was never registered as a [Route] on a component.
Source
Thrown at src/Components/Components/src/Routing/RouteTableFactory.cs:190
var templates = GetTemplates(pageType);
var result = ComputeTemplateGroupInfo(templates);
RoutePattern? parsedTemplate = null;
HashSet<string>? routeParameterNames = null;
for (var i = 0; i < result.ParsedTemplates.Length; i++)
{
var (parsed, parameters) = result.ParsedTemplates[i];
if (string.Equals(parsed.RawText, template, StringComparison.OrdinalIgnoreCase))
{
parsedTemplate = parsed;
routeParameterNames = parameters;
break;
}
}
if (parsedTemplate == null)
{
throw new InvalidOperationException($"Unable to find the provided template '{template}'");
}
return new InboundRouteEntry()
{
Handler = pageType,
RoutePattern = parsedTemplate,
UnusedRouteParameterNames = GetUnusedParameterNames(result.AllRouteParameterNames, routeParameterNames!),
};
}
private static void DetectAmbiguousRoutes(TreeRouteBuilder builder)
{
var seen = new HashSet<InboundRouteEntry>(new InboundRouteEntryAmbiguityEqualityComparer());
seen.EnsureCapacity(builder.InboundEntries.Count);
for (var i = 0; i < builder.InboundEntries.Count; i++)
{
var current = builder.InboundEntries[i];
View on GitHub (pinned to 3600ca084e)
Solutions
- Confirm the template string exactly matches a [Route(...)] attribute in one of the assemblies supplied to RouteTableFactory (case-insensitive, including leading/trailing slashes).
- Ensure the assembly containing the route is included in the AppAssembly / AdditionalAssemblies passed to the Router.
- Search the codebase for [Route("<template>")] to confirm the attribute exists and is spelled identically.
- If the route is dynamic, register a matching template attribute on a component before requesting it.
Example fix
// before — typo in requested template
var entry = factory.GetEntry("usrs/{id}", pageType); // no [Route("usrs/{id}")] exists
// after
var entry = factory.GetEntry("users/{id}", pageType); // matches [Route("users/{id}")] Defensive patterns
Strategy: validation
Validate before calling
// Confirm a template is registered before requesting it from RouteTableFactory.
bool IsRegistered(IEnumerable<string> templates, string requested)
=> templates.Any(t => string.Equals(t, requested, StringComparison.OrdinalIgnoreCase)); Prevention
- Search the codebase for [Route("<template>")] / @page "<template>" to confirm a template exists.
- Include every assembly that declares routes in AppAssembly / AdditionalAssemblies.
- Centralize template strings in a constants class to avoid drift.
- Add a test that lists all expected templates and asserts each resolves.
When it happens
Trigger: Calling the internal RouteTableFactory with a template string that does not match any [Route("...")] attribute present in the supplied assemblies. Common from hot-reload invalidation, programmatic route generation, or unit tests that pass arbitrary template strings.
Common situations: Adding a [Route] attribute with a typo and referencing the corrected string elsewhere; referencing a route that lives in an assembly not passed to the factory; renaming a route template in code but keeping the old string in a lookup table; multi-assembly apps where the route was contributed by an optional plugin that is not loaded.
Related errors
- The following routes are ambiguous: '{existingText}' in '{ex
- The {nameof(RouteView)} component requires a non-null value
- The {nameof(Router)} component requires a value for the para
- The {nameof(Router)} component requires a value for the para
- Setting {nameof(NotFound)} and {nameof(NotFoundPage)} proper
AI-assisted analysis of dotnet/aspnetcore@3600ca084e (2026-08-11).
Data as JSON: /api/errors/fbec70d524fb3bb3.
Report an issue: GitHub.