Skip to content

Reflection fails to bind preserved tuples after closing a generic test method #7482

Closed

Description

@thomhurst

Summary

A generic test accepting (T, object) passes with a method data source returning (int, string) in source-generated mode but fails during invocation in reflection mode. Reflection infers the type argument correctly but passes the original incompatible value tuple to the closed method.

Reproduction

Add this class to a TUnit test project:

public class TupleBindingTests
{
    public static (int, string) Row() => (1, "text");
    [Test, MethodDataSource(nameof(Row))]
    public void Test<T>((T, object) row) { }
}

Run the class normally, then with --reflection.

Expected and actual

Both modes should bind the tuple after inferring T = int. Generated mode passes. Reflection throws ArgumentException: System.ValueTuple<int, string> cannot be converted to System.ValueTuple<int, object>.

The tuple is preserved before inference, but the reflection invoker never reconstructs it after the method closes. The invoker on current main passes the preserved tuple through its ordinary argument-casting path. The flattened-row reconstruction added by the still-open #7469 also does not handle this one-argument preserved tuple.

Environment

.NET SDK 10.0.403, net10.0, macOS arm64. Reproduced at merge base 67870ed and on e1d8214; this predates #7469. Generated mode passes on the PR head.

Remaining work and acceptance criteria

  • Normalize preserved tuple rows against the closed method parameter types after generic inference, preserving already compatible tuples.
  • Run the reproduction in source-generated and reflection modes, asserting T = int and both tuple element values.
  • Keep repeated generic-bound inference changes in Reflection rejects convertible types for a repeated generic tuple parameter #7481; this issue must work independently for the unambiguous (T, object) case.

This is the binding prerequisite for #7481. #7469 is related work, not a closing fix for this issue.

Found while reviewing #7469.

Activity

  1. added
    bugSomething isn't working
    P2Medium: edge case, mode divergence, flaky test, or workaround exists
    on Nov 3, 2026
  2. thomhurst commented on Nov 3, 2026

    @thomhurst
    OwnerAuthor

    Triaged against origin/main at 1f70564. DataUnwrapper.UnwrapWithTypesInternal preserves a single tuple parameter; ReflectionTestDataCollector.CreateReflectionTestInvoker closes the method, then uses ordinary argument casting before Invoke. The preserved tuple therefore still needs normalization to the closed tuple type. Clarified acceptance criteria and its role as #7481's binding prerequisite. #7469 remains open and does not deliver this generic binding fix.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium: edge case, mode divergence, flaky test, or workaround existsbugSomething isn't workingin-progressWork is in progress

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions