{"record":{"id":"03916de243fb478e","repo":"dotnet/aspnetcore","slug":"the-type-notfoundpage-fullname-does-not-have-a-m","errorCode":null,"errorMessage":"The type {NotFoundPage.FullName} does not have a Microsoft.AspNetCore.Components.RouteAttribute applied to it.","messagePattern":"The type (.+?) does not have a Microsoft\\.AspNetCore\\.Components\\.RouteAttribute applied to it\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Components/Components/src/Routing/Router.cs","lineNumber":155,"sourceCode":"\n        if (NotFoundPage != null)\n        {\n#pragma warning disable CS0618 // Type or member is obsolete\n            if (NotFound != null)\n            {\n                throw new InvalidOperationException($\"Setting {nameof(NotFound)} and {nameof(NotFoundPage)} properties simultaneously is not supported. Use either {nameof(NotFound)} or {nameof(NotFoundPage)}.\");\n            }\n#pragma warning restore CS0618 // Type or member is obsolete\n            if (!typeof(IComponent).IsAssignableFrom(NotFoundPage))\n            {\n                throw new InvalidOperationException($\"The type {NotFoundPage.FullName} \" +\n                    $\"does not implement {typeof(IComponent).FullName}.\");\n            }\n\n            var routeAttributes = NotFoundPage.GetCustomAttributes(typeof(RouteAttribute), inherit: true);\n            if (routeAttributes.Length == 0)\n            {\n                throw new InvalidOperationException($\"The type {NotFoundPage.FullName} \" +\n                    $\"does not have a {typeof(RouteAttribute).FullName} applied to it.\");\n            }\n\n            var routeAttribute = (RouteAttribute)routeAttributes[0];\n            if (routeAttribute.Template != null)\n            {\n                _notFoundPageRoute = routeAttribute.Template;\n            }\n        }\n\n        if (!_onNavigateCalled)\n        {\n            _onNavigateCalled = true;\n            await RunOnNavigateAsync(NavigationManager.ToBaseRelativePath(_locationAbsolute), isNavigationIntercepted: false);\n        }\n        else\n        {\n            Refresh(isNavigationIntercepted: false);","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/294cab2f9b2e03af6b953820c7ab497c3c8b7ad9/src/Components/Components/src/Routing/Router.cs#L137-L173","documentation":"Thrown in Router.SetParametersAsync when NotFoundPage is set but the type has no [RouteAttribute] (i.e., no @page directive). The Router reads the type's [Route] attribute to derive the not-found route; without one it cannot route to it, so it rejects the configuration.","triggerScenarios":"Setting NotFoundPage=\"@typeof(NotFound)\" where NotFound.razor lacks an @page directive. The Router expects at least one [Route] on the type to use as its _notFoundPageRoute.","commonSituations":"Creating a dedicated 404 component but forgetting @page; an older sample where the 404 page had no route; refactoring that removed the @page line.","solutions":["Add a @page directive to the NotFoundPage component, e.g. @page \"/404\" (the exact path is not critical; the Router uses it as the route key).","Confirm the [Route] attribute is present via NotFoundPage.GetCustomAttributes(typeof(RouteAttribute), inherit: true).","Rebuild so the route attribute is emitted on the generated component class."],"exampleFix":"<!-- before: NotFound.razor -->\n<h1>Not found</h1>\n\n<!-- after: NotFound.razor -->\n@page \"/404\"\n<h1>Not found</h1>","handlingStrategy":"validation","validationCode":"static bool HasRouteAttribute(Type t) =>\n    t.GetCustomAttributes(typeof(RouteAttribute), inherit: true).Length > 0;\n// Only bind NotFoundPage if it has a [Route]/@page.\n<Router ... NotFoundPage=\"@(HasRouteAttribute(typeof(NotFound)) ? typeof(NotFound) : null)\" />","typeGuard":"static bool IsRoutedComponent(Type t) =>\n    typeof(IComponent).IsAssignableFrom(t) &&\n    t.GetCustomAttributes(typeof(RouteAttribute), inherit: true).Length > 0;","tryCatchPattern":null,"preventionTips":["Always add an @page directive to the component passed to NotFoundPage.","Add a test asserting NotFoundPage has a [Route] attribute.","Rebuild after editing .razor so the route attribute is regenerated."],"tags":["blazor","routing","router","notfound","routeattribute","configuration"],"analyzedSha":"294cab2f9b2e03af6b953820c7ab497c3c8b7ad9","analyzedAt":"2026-08-06T20:08:02.189Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}