{"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/294cab2f9b2e03af6b953820c7ab497c3c8b7ad9/src/Components/Components/src/DynamicComponent.cs#L68-L104","documentation":"Thrown by DynamicComponent.SetParametersAsync when the Type parameter is null after all parameters are processed. DynamicComponent needs to know which component to render; without a Type it cannot proceed. Although Type is marked [EditorRequired], the runtime still enforces non-null explicitly at DynamicComponent.cs:84-87.","triggerScenarios":"Using <DynamicComponent> without a Type attribute, or binding Type to a variable/expression that evaluates to null (e.g., a Type selected from a list that has no selection).","commonSituations":"Conditional rendering where the component type hasn't been selected yet; binding Type to a null property; forgetting to set Type in markup.","solutions":["Always supply a non-null Type: <DynamicComponent Type=\"@someNonNullType\" />.","Guard the DynamicComponent behind an @if(type is not null) so it only renders when Type is known.","Initialize the bound Type property to a concrete default component type."],"exampleFix":"// before\n<DynamicComponent Type=\"@SelectedType\" />\n@code { private Type? SelectedType; /* null initially */ }\n\n// after\n@if (SelectedType is not null)\n{\n    <DynamicComponent Type=\"@SelectedType\" />\n}","handlingStrategy":"validation","validationCode":"if (Type is null)\n    throw new InvalidOperationException(\"DynamicComponent requires a non-null Type.\");","typeGuard":"static bool HasValidType(Type? t) => t is not null && typeof(IComponent).IsAssignableFrom(t);","tryCatchPattern":null,"preventionTips":["Guard DynamicComponent with @if(type is not null) in markup.","Initialize the bound Type property to a concrete default component."],"tags":["blazor","dynamic-component","parameter-binding","null-reference"],"analyzedSha":"294cab2f9b2e03af6b953820c7ab497c3c8b7ad9","analyzedAt":"2026-08-06T20:08:02.189Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}