{"record":{"id":"7b275ea4c39c85dc","repo":"dotnet/aspnetcore","slug":"nameof-dynamiccomponent-requires-a-non-null-val","errorCode":null,"errorMessage":"{nameof(DynamicComponent)} requires a non-null value for the parameter {nameof(Type)}.","messagePattern":"(.+?) requires a non-null value for the parameter (.+?)\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Components/Components/src/DynamicComponent.cs","lineNumber":86,"sourceCode":"        {\n            if (entry.Name.Equals(nameof(Type), StringComparison.OrdinalIgnoreCase))\n            {\n                Type = (Type)entry.Value;\n            }\n            else if (entry.Name.Equals(nameof(Parameters), StringComparison.OrdinalIgnoreCase))\n            {\n                Parameters = (IDictionary<string, object>)entry.Value;\n            }\n            else\n            {\n                throw new InvalidOperationException(\n                    $\"{nameof(DynamicComponent)} does not accept a parameter with the name '{entry.Name}'. To pass parameters to the dynamically-rendered component, use the '{nameof(Parameters)}' parameter.\");\n            }\n        }\n\n        if (Type is null)\n        {\n            throw new InvalidOperationException($\"{nameof(DynamicComponent)} requires a non-null value for the parameter {nameof(Type)}.\");\n        }\n\n        _renderHandle.Render(_cachedRenderFragment);\n        return Task.CompletedTask;\n    }\n\n    void Render(RenderTreeBuilder builder)\n    {\n        builder.OpenComponent(0, Type);\n\n        if (Parameters != null)\n        {\n            foreach (var entry in Parameters)\n            {\n                builder.AddComponentParameter(1, entry.Key, entry.Value);\n            }\n        }\n","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/Components/Components/src/DynamicComponent.cs#L68-L104","documentation":"DynamicComponent requires a non-null Type parameter naming the component to render. Omitting it leaves the component with nothing to render, which is rejected with InvalidOperationException.","triggerScenarios":"<DynamicComponent /> or <DynamicComponent Parameters=\"@p\" /> without a Type, or Type bound to a variable that is null at render time.","commonSituations":"Type bound to a runtime-resolved value that is initially null, conditional Type that evaluates to null, or forgetting the attribute.","solutions":["Always supply a non-null Type attribute.","Guard the DynamicComponent with @if(type is not null) so it only renders when a type is available.","Provide a fallback/default component type."],"exampleFix":"// before\n<DynamicComponent Type=\"@maybeNullType\" />\n// after\n@if(maybeNullType is not null)\n{\n    <DynamicComponent Type=\"@maybeNullType\" />\n}","handlingStrategy":"validation","validationCode":"// Guard DynamicComponent so it only renders with a non-null Type.\n@if (componentType is not null)\n{\n    <DynamicComponent Type=\"@componentType\" />\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always supply Type, or guard the markup with @if(type is not null).","Provide a default/fallback component type when the dynamic type is unknown.","Avoid binding Type to expressions that can evaluate to null."],"tags":["blazor","dynamic-component","parameters","required"],"backgroundTag":null,"analyzedSha":"3600ca084e9c8b5f4174fc5e747f4c52d2100806","analyzedAt":"2026-08-11T16:32:30.678Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}