diff --git a/src/EFCore/Metadata/Conventions/NonNullableConventionBase.cs b/src/EFCore/Metadata/Conventions/NonNullableConventionBase.cs index 01060dc2b8f..eff4a3d30da 100644 --- a/src/EFCore/Metadata/Conventions/NonNullableConventionBase.cs +++ b/src/EFCore/Metadata/Conventions/NonNullableConventionBase.cs @@ -57,10 +57,13 @@ protected virtual bool IsNonNullableReferenceType( var state = GetOrInitializeState(modelBuilder); // First check for [MaybeNull] on the return value. If it exists, the member is nullable. + // Note: avoid using GetCustomAttribute<> below because of https://github.com/mono/mono/issues/17477 var isMaybeNull = memberInfo switch { - FieldInfo f => f.GetCustomAttribute() != null, - PropertyInfo p => p.GetMethod?.ReturnParameter?.GetCustomAttribute() != null, + FieldInfo f + => f.CustomAttributes.Any(a => a.AttributeType == typeof(CA.MaybeNullAttribute)), + PropertyInfo p + => p.GetMethod?.ReturnParameter?.CustomAttributes?.Any(a => a.AttributeType == typeof(CA.MaybeNullAttribute)) == true, _ => false };