diff --git a/Src/FluentAssertions/Common/TypeExtensions.cs b/Src/FluentAssertions/Common/TypeExtensions.cs index 8d4f0fdc36..ef04fef9e2 100644 --- a/Src/FluentAssertions/Common/TypeExtensions.cs +++ b/Src/FluentAssertions/Common/TypeExtensions.cs @@ -588,12 +588,12 @@ private static bool IsAnonymousType(this Type type) public static bool IsRecord(this Type type) { return TypeIsRecordCache.GetOrAdd(type, static t => - t.GetMethod("$") is not null && - t.GetTypeInfo() - .DeclaredProperties - .FirstOrDefault(p => p.Name == "EqualityContract")? - .GetMethod? - .GetCustomAttribute(typeof(CompilerGeneratedAttribute)) is not null); + { + return t.GetMethod("$", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) is { } && + t.GetProperty("EqualityContract", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)? + .GetMethod? + .GetCustomAttribute(typeof(CompilerGeneratedAttribute)) is { }; + }); } private static bool IsKeyValuePair(Type type)