diff --git a/src/Riok.Mapperly/Descriptors/Enumerables/CollectionInfoBuilder.cs b/src/Riok.Mapperly/Descriptors/Enumerables/CollectionInfoBuilder.cs index c3708019b1..eb8f9e6b9c 100644 --- a/src/Riok.Mapperly/Descriptors/Enumerables/CollectionInfoBuilder.cs +++ b/src/Riok.Mapperly/Descriptors/Enumerables/CollectionInfoBuilder.cs @@ -110,6 +110,11 @@ ITypeSymbol enumeratedType private static ITypeSymbol? GetEnumeratedType(WellKnownTypes types, ITypeSymbol type) { + // if type is array return element type + // otherwise using the IEnumerable element type can erase the null annotation for external types + if (type.IsArrayType()) + return ((IArrayTypeSymbol)type).ElementType; + if (type.ImplementsGeneric(types.Get(typeof(IEnumerable<>)), out var enumerableIntf)) return enumerableIntf.TypeArguments[0];