{"record":{"id":"fd46f7e141045b1a","repo":"dotnet/aspnetcore","slug":"the-component-activator-returned-a-null-value-for","errorCode":null,"errorMessage":"The component activator returned a null value for a component of type {componentType.FullName}.","messagePattern":"The component activator returned a null value for a component of type (.+?)\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Components/Components/src/ComponentFactory.cs","lineNumber":81,"sourceCode":"        {\n            // Typical case where no rendermode is specified in either location. We don't call ResolveComponentForRenderMode in this case.\n            component = _componentActivator.CreateInstance(componentType);\n        }\n        else\n        {\n            // At least one rendermode is specified. We require that it's exactly one, and use ResolveComponentForRenderMode with it.\n            var effectiveRenderMode = callerSpecifiedRenderMode is null\n                ? componentTypeRenderMode!\n                : componentTypeRenderMode is null\n                    ? callerSpecifiedRenderMode\n                    : throw new InvalidOperationException($\"The component type '{componentType}' has a fixed rendermode of '{componentTypeRenderMode}', so it is not valid to specify any rendermode when using this component.\");\n            component = _renderer.ResolveComponentForRenderMode(componentType, parentComponentId, _componentActivator, effectiveRenderMode);\n        }\n\n        if (component is null)\n        {\n            // The default activator/resolver will never do this, but an externally-supplied one might\n            throw new InvalidOperationException($\"The component activator returned a null value for a component of type {componentType.FullName}.\");\n        }\n\n        if (!_propertyInjectionDisabled)\n        {\n            PerformPropertyInjection(serviceProvider, component);\n        }\n\n        return component;\n    }\n\n    private void PerformPropertyInjection(IServiceProvider serviceProvider, IComponent instance)\n    {\n        // Suppressed with \"pragma warning disable\" so ILLink Roslyn Anayzer doesn't report the warning.\n#pragma warning disable IL2072 // 'componentType' argument does not satisfy 'DynamicallyAccessedMemberTypes.All' in call to 'IComponentPropertyActivator.GetActivator(Type)'.\n        var propertyActivator = _propertyActivator.GetActivator(instance.GetType());\n#pragma warning restore IL2072\n\n        propertyActivator(serviceProvider, instance);","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/Components/Components/src/ComponentFactory.cs#L63-L99","documentation":"A custom IComponentActivator.CreateInstance returned null for a component type. The default activator never does this, but a user-supplied or DI-based activator might. ComponentFactory treats a null result as a fatal misconfiguration.","triggerScenarios":"Custom IComponentActivator that returns null for some component types, or a DI container resolving to null due to a missing or failing registration.","commonSituations":"Buggy custom activator, conditional activation logic that falls through without returning, or a DI scope/lifetime mismatch causing resolution to fail silently.","solutions":["Fix the custom activator to never return null; throw on unknown types instead.","Fall back to the default activation path when the custom path cannot resolve the type.","Add null-check logging in the activator to catch which type fails to resolve."],"exampleFix":"// before\npublic IComponent CreateInstance(Type t) => _custom.TryGetValue(t, out var c) ? c : null;\n// after\npublic IComponent CreateInstance(Type t) => _custom.TryGetValue(t, out var c) ? c : _default.CreateInstance(t);","handlingStrategy":"try-catch","validationCode":"// Inspect the activator contract; ensure it never returns null.\nif (activator.CreateInstance(type) is null) throw new InvalidOperationException(\"Activator returned null.\");","typeGuard":null,"tryCatchPattern":"try { component = factory.CreateComponent(type, ...); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"returned a null value\"))\n{\n    _logger.LogError(ex, \"Custom activator returned null for {Type}\", type);\n    throw;\n}","preventionTips":["Custom IComponentActivator implementations must never return null; throw instead.","Add unit tests asserting non-null results for all expected component types.","Log the failing type inside the activator to aid diagnosis."],"tags":["blazor","di","component-activator","null-guard"],"backgroundTag":null,"analyzedSha":"3600ca084e9c8b5f4174fc5e747f4c52d2100806","analyzedAt":"2026-08-11T16:32:30.678Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}