From 6b5f99e9943cab9d4adc1f318f17b00067ca8ced Mon Sep 17 00:00:00 2001 From: Tom Longhurst <30480171+thomhurst@users.noreply.github.com> Date: Thu, 19 Feb 2026 00:19:35 +0000 Subject: [PATCH] fix: add missing AOT trimming suppressions and null safety for type names Add [UnconditionalSuppressMessage] for IL2075 on PropertyInjector methods that call GetProperty() on ContainingType, which is already annotated with [DynamicallyAccessedMembers] in PropertyInjectionMetadata. Fix null safety in JsonExtensions where FullName can be null for generic type parameters by falling back to Name before "Unknown". Closes #4856 --- TUnit.Engine/Extensions/JsonExtensions.cs | 4 ++-- TUnit.Engine/Services/PropertyInjector.cs | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/TUnit.Engine/Extensions/JsonExtensions.cs b/TUnit.Engine/Extensions/JsonExtensions.cs index b01e75aa5b..5c67caad17 100644 --- a/TUnit.Engine/Extensions/JsonExtensions.cs +++ b/TUnit.Engine/Extensions/JsonExtensions.cs @@ -65,7 +65,7 @@ public static TestJson ToJsonModel(this TestContext context) classParamTypeNames = new string[classParameterTypes.Length]; for (var i = 0; i < classParameterTypes.Length; i++) { - classParamTypeNames[i] = classParameterTypes[i].FullName ?? "Unknown"; + classParamTypeNames[i] = classParameterTypes[i]?.FullName ?? classParameterTypes[i]?.Name ?? "Unknown"; } } else @@ -77,7 +77,7 @@ public static TestJson ToJsonModel(this TestContext context) var methodParamTypeNames = new string[methodParameters.Length]; for (var i = 0; i < methodParameters.Length; i++) { - methodParamTypeNames[i] = methodParameters[i].Type.FullName ?? "Unknown"; + methodParamTypeNames[i] = methodParameters[i].Type?.FullName ?? methodParameters[i].Type?.Name ?? "Unknown"; } return new TestJson diff --git a/TUnit.Engine/Services/PropertyInjector.cs b/TUnit.Engine/Services/PropertyInjector.cs index a6492ad786..16f0c1afa5 100644 --- a/TUnit.Engine/Services/PropertyInjector.cs +++ b/TUnit.Engine/Services/PropertyInjector.cs @@ -230,6 +230,7 @@ private Task InjectSourceGeneratedPropertiesAsync( } [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Source-gen properties are AOT-safe")] + [UnconditionalSuppressMessage("Trimming", "IL2075", Justification = "ContainingType is annotated with DynamicallyAccessedMembers in PropertyInjectionMetadata")] private async Task InjectSourceGeneratedPropertyAsync( object instance, PropertyInjectionMetadata metadata, @@ -376,6 +377,7 @@ private Task RecurseIntoNestedPropertiesAsync( return Task.CompletedTask; } + [UnconditionalSuppressMessage("Trimming", "IL2075", Justification = "ContainingType is annotated with DynamicallyAccessedMembers in PropertyInjectionMetadata")] private async Task RecurseIntoNestedPropertiesCoreAsync(object instance, PropertyInjectionPlan plan, ConcurrentDictionary objectBag, MethodMetadata? methodMetadata, TestContextEvents events, ConcurrentDictionary visitedObjects, CancellationToken cancellationToken)