Skip to content

GenerateMock silently produces no type and no diagnostic for large interfaces #6604

Description

@thomhurst

When [assembly: TUnit.Mocks.GenerateMock(typeof(T))] is applied to a large interface, the source generator produces no output and emits no diagnostic. The attribute line itself compiles (proving the type is accessible), but the generated TMockable type simply does not exist, causing CS0246 at every usage site with no indication of what went wrong.

To reproduce

  1. Add GenerateMock for a large SDK-generated interface — e.g. one with 100+ method overloads
  2. The attribute compiles without error
  3. Reference TMockable anywhere in the project
  4. Build → CS0246: The type or namespace name 'TMockable' could not be found

Switching to a smaller interface (e.g. one with ~30 methods) works correctly with identical setup.

Expected behavior

Either the mock is generated, or a diagnostic is emitted explaining why generation failed:

▎ TUnit.Mocks: failed to generate mock for 'T'. [reason]

Actual behavior

No generated type. No warning. No error from the generator. Only a CS0246 at the call site with no pointer to the root cause.

Additional context

The failure appears to be interface-size-dependent. The generator likely hits an internal limit or encounters an unhandled exception on a specific method signature and swallows it. A diagnostic on failure would make this immediately debuggable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions