Skip to content

Comments

fix: TypeExtensions.GetMetadataName handles null Namespace (#4866)#4905

Merged
thomhurst merged 1 commit intomainfrom
fix/type-extensions-null
Feb 19, 2026
Merged

fix: TypeExtensions.GetMetadataName handles null Namespace (#4866)#4905
thomhurst merged 1 commit intomainfrom
fix/type-extensions-null

Conversation

@thomhurst
Copy link
Owner

Summary

  • Fix TypeExtensions.GetMetadataName producing "null.TypeName" when a type is in the root (global) namespace
  • When Type.Namespace is null or empty, the method now returns just type.Name instead of $"{type.Namespace}.{type.Name}"

Closes #4866

Test plan

  • Verified the project builds successfully with dotnet build TUnit.Analyzers/TUnit.Analyzers.csproj
  • Confirm analyzer correctly resolves metadata names for types in the root namespace
  • Confirm analyzer still correctly resolves metadata names for types in named namespaces

When a type is in the root (global) namespace, Type.Namespace is null,
causing GetMetadataName to produce "null.TypeName". Now returns just
the type name when Namespace is null or empty.
@claude
Copy link
Contributor

claude bot commented Feb 19, 2026

Code Review

The fix correctly handles the null namespace case in TUnit.Analyzers. However, there is an identical copy of the GetMetadataName method in the source generator that has not been updated:

TUnit.Core.SourceGenerator/Extensions/TypeExtensions.cs still contains the unfixed version:

public static string GetMetadataName(this Type type)
{
    return $"{type.Namespace}.{type.Name}";  // still produces "null.TypeName" for root-namespace types
}

This means types in the global/root namespace will still produce malformed metadata names ("null.TypeName") when processed through the source generator code path. The same one-line fix should be applied there:

return string.IsNullOrEmpty(type.Namespace) ? type.Name : $"{type.Namespace}.{type.Name}";

Reference:

public static string GetMetadataName(this Type type)
{
return $"{type.Namespace}.{type.Name}";
}

@thomhurst thomhurst merged commit a5f6b5e into main Feb 19, 2026
14 checks passed
@thomhurst thomhurst deleted the fix/type-extensions-null branch February 19, 2026 01:04
This was referenced Feb 22, 2026
This was referenced Feb 23, 2026
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.

fix: TypeExtensions.GetMetadataName produces 'null.TypeName' for root namespace types

1 participant