Skip to content

Fix IndexOutOfRangeException when an Enum's MetadataToken collides with Nullable<T> - #513

Merged
SergeiPavlov merged 3 commits into
master-servicetitanfrom
fix-metadatatoken-collision
Aug 27, 2026
Merged

Fix IndexOutOfRangeException when an Enum's MetadataToken collides with Nullable<T>#513
SergeiPavlov merged 3 commits into
master-servicetitanfrom
fix-metadatatoken-collision

Conversation

@SergeiPavlov

@SergeiPavlov SergeiPavlov commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

Copy of DataObjects-NET#472


Note

Medium Risk
Changes core packed-tuple field accessor resolution; behavior is narrowed to fix a rare token collision bug, with regression tests covering the edge case.

Overview
Fixes IndexOutOfRangeException during TupleDescriptor.Create when a tuple field type is an enum whose MetadataToken matches Nullable<T> but lives in a different module.

In TupleLayout.ValueFieldAccessorResolver.GetValue, nullable unwrap for enum underlying-type resolution now requires both the known Nullable<> metadata token and the same module as WellKnownTypes.NullableOfT, instead of token alone. That stops non-generic enums from being treated like Nullable<> and calling GetGenericArguments()[0] on them.

Adds NullableTokenCollisionTest, which emits filler types so a dynamic enum shares Nullable<>’s token in another assembly, and asserts tuple descriptor creation for the plain enum and for Nullable<that enum> both succeed.

Reviewed by Cursor Bugbot for commit bbe91de. Bugbot is set up for automated code reviews on this repo. Configure here.

@SergeiPavlov
SergeiPavlov merged commit 0a42abd into master-servicetitan Aug 27, 2026
8 checks passed
@SergeiPavlov
SergeiPavlov deleted the fix-metadatatoken-collision branch August 27, 2026 00:37
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.

3 participants