diff --git a/TUnit.Core/Discovery/ObjectGraphDiscoverer.cs b/TUnit.Core/Discovery/ObjectGraphDiscoverer.cs index e91cd28eb8..b281c19b8f 100644 --- a/TUnit.Core/Discovery/ObjectGraphDiscoverer.cs +++ b/TUnit.Core/Discovery/ObjectGraphDiscoverer.cs @@ -651,8 +651,13 @@ private static bool IsDirectProperty(string cacheKey, HashSet hierarchyT return true; // Malformed key, treat as direct } +#if NET9_0_OR_GREATER + var declaringTypeName = cacheKey.AsSpan()[..lastDotIndex]; + return hierarchyTypes.GetAlternateLookup>().Contains(declaringTypeName); +#else var declaringTypeName = cacheKey.Substring(0, lastDotIndex); return hierarchyTypes.Contains(declaringTypeName); +#endif } ///