Skip to content

Fix: Unity RegisterComponent with Keyed Throws Exception#842

Open
Selakz wants to merge 1 commit intohadashiA:masterfrom
Selakz:fix-force-inject-execution
Open

Fix: Unity RegisterComponent with Keyed Throws Exception#842
Selakz wants to merge 1 commit intohadashiA:masterfrom
Selakz:fix-force-inject-execution

Conversation

@Selakz
Copy link
Copy Markdown

@Selakz Selakz commented Feb 25, 2026

This pull request is related to issue #794.

The Problem:
In the current implementation of RegisterComponent and RegisterComponentInHierarchy, a build callback is registered to force injection by calling container.Resolve(). However, it ignores the key that might be subsequently configured via .Keyed(key). This leads to a VContainerException during the build phase because the container tries to resolve a default (unkeyed) registration that doesn't exist. Also, the keyed registration will not be force injected.

Though the main purpose of RegisterComponent is to trigger auto-injection, since it returns a RegistrationBuilder, I believe ensuring it respects the key parameter is important for internal state consistency.

The Solution:
Passed registrationBuilder.Key into the Resolve method within the build callback. Since the default value of the key parameter in Resolve is null, I think this change is backward compatible and correctly handles both keyed and non-keyed registrations.

@vercel
Copy link
Copy Markdown

vercel bot commented Feb 25, 2026

@Selakz is attempting to deploy a commit to the hadashia's projects Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant