From 098049799c41a1b9979a8c960a9450050bb00e70 Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Wed, 14 Oct 2020 21:17:04 +0300 Subject: [PATCH] Work around mono bug affecting Xamarin Android (#22982) (#22995) Fixes #22665 (cherry picked from commit fbc11f26134e6c283cb785c80a88447863e14ea8) --- .../Metadata/Conventions/NonNullableConventionBase.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 };