Skip to content

[Bug]: Missing global:: prefix on TUnit.Core type references causes namespace resolution failures. #4602

@Xen0byte

Description

@Xen0byte

Description

Not entirely sure whether this is a bug or a feature request, but...

When code generators emit code that references TUnit.Core types, they probably should consistently use the global:: prefix for all type references. Without this, projects with certain namespace patterns will fail to compile due to C# namespace resolution rules.

Expected Behavior

Code generators that emit TUnit test code should probably always use the global:: prefix for all TUnit.Core type references.

Actual Behavior

C# namespace resolution walks up the namespace hierarchy before checking global scope. If a project's namespace contains TUnit as a segment (e.g. MySolution.TUnit.Tests), then a reference to TUnit.Core.SomeType will first look for MySolution.TUnit.Core.SomeType, which doesn't exist.

Steps to Reproduce

namespace MySolution.TUnit.Tests
{
    public class MyTestClass
    {
        [global::TUnit.Core.BeforeAttribute(TUnit.Core.HookType.Class)]
        public void Setup() { }
    }
}

This code fails, as C# looks for MySolution.TUnit.Core.HookType first.

error CS0234: The type or namespace name "Core" does not exist in the namespace "MySolution.TUnit"

TUnit Version

1.12.82

.NET Version

.NET 10

Operating System

Windows

IDE / Test Runner

dotnet CLI (dotnet test / dotnet run)

Error Output / Stack Trace

CS0234 The type or namespace name 'Core' does not exist in the namespace 'Reqnroll.Retry.TUnit' (are you missing an assembly reference?)

Additional Context

A (potentially incomplete) list of types for which this reproduces includes:

  • TUnit.Core.HookType
  • TUnit.Core.TestContext
  • TUnit.Core.RetryAttribute
  • TUnit.Core.TestAttribute

IDE-Specific Issue?

  • I've confirmed this issue occurs when running via dotnet test or dotnet run, not just in my IDE

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