GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — TUnit.Mocks: generated mock fails to compile when a generic method's type parameter name matches the interface's type parameter · Issue #7299 · thomhurst/TUnit

TUnit.Mocks: generated mock fails to compile when a generic method's type parameter name matches the interface's type parameter #7299

New issue
Copy link
New issue
Copy link
Closed
#7303
Closed
TUnit.Mocks: generated mock fails to compile when a generic method's type parameter name matches the interface's type parameter#7299
#7303
Copy link
Labels
bugSomething isn't working

Description

@thomhurst
thomhurst
opened on Oct 31, 2026
Issue body actions

Description

When a generic interface's type parameter has the same name as a type parameter on one of its (inherited) generic methods, the TUnit.Mocks source generator emits code that does not compile.

Real-world trigger: Wolverine.EntityFrameworkCore.IDbContextOutbox<T>, which inherits IMessageBus.InvokeAsync<T>(...).

Repro (TUnit.Mocks 1.76.45, net10.0)

public interface IBus { T Invoke<T>(object message); }
public interface IOutbox<T> : IBus { T Db { get; } }

public class Tests
{
    [Test]
    public void Repro()
    {
        var mock = Mock.Of<IOutbox<string>>();
        mock.Db.Returns("x");
    }
}

Errors (all in generated IOutbox_T_* files)

CS9289: Type parameter 'T' has the same name as an extension container type parameter   (x8)
CS0229: Ambiguity between 'T' and 'T'                                                    (x20)
CS0692: Duplicate type parameter 'T'                                                     (x2)
CS0311: The type 'IOutbox_T__Invoke_M1_MockCall<IOutbox_T__Invoke_M1_MockCall<T, T>.T, ...>' cannot be used as type parameter 'TSelf' ...

Expected

The generator renames (or otherwise disambiguates) method type parameters that collide with the containing type's / extension block's type parameters, and the mock compiles.

Workaround

Declare a closed, non-generic sub-interface and mock that instead:

public interface IStringOutbox : IOutbox<string> { }
var mock = Mock.Of<IStringOutbox>();
IOutbox<string> outbox = mock.Object;

Activity

  1. thomhurst
    added
    bugSomething isn't working
    on Oct 31, 2026
  2. thomhurst
    closed this as completedin #7303on Oct 31, 2026
  3. Quattordici
    added a commit that references this issue on Nov 2, 2026

    fix(mocks): rename method type parameters that collide with the mocke…

    This issue will close once commit 7497a97 is merged into the 'main' branch.
    7497a97
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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402792 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.