When migrating from AutoMapper v14 to Mapster, I encountered a difference in behavior regarding null propagation for collection properties during mapping.
In AutoMapper, if a source collection property is null, calling LINQ methods like .Select() inside a mapping expression does not throw an exception — it returns null for the destination property. However, in Mapster, the same expression throws System.ArgumentNullException: 'Value cannot be null. (Parameter 'source')'.
It seems that Mapster does not apply null propagation automatically in such cases, even though the destination property is nullable.
Reproduction Steps
apster;
using MapsterMapper;
var config = new TypeAdapterConfig();
config.ForType<Source, Destination>()
.Map(s => s.ProductNames, d => d.Products.Select(p => p.Name).ToArray());
var mapper = new Mapper(config);
var source1 = new Source();
var destination1 = mapper.Map<Source, Destination>(source1); //throws System.ArgumentNullException: 'Value cannot be null. (Parameter 'source')
class Source
{
public Product[]? Products { get; set; }
}
class Product
{
public required string Name { get; set; }
}
class Destination
{
public string[]? ProductNames { get; set; }
}
Expected Behavior
The mapping should return null for Destination.ProductNames when Source.Products is null, similar to AutoMapper's behavior. Null propagation should be applied by default, or at least be configurable.
Actual Behavior
System.ArgumentNullException: 'Value cannot be null. (Parameter 'source')' is thrown at runtime.
Environment
Mapster version: 10.0.11
When migrating from AutoMapper v14 to Mapster, I encountered a difference in behavior regarding null propagation for collection properties during mapping.
In AutoMapper, if a source collection property is null, calling LINQ methods like .Select() inside a mapping expression does not throw an exception — it returns null for the destination property. However, in Mapster, the same expression throws
System.ArgumentNullException: 'Value cannot be null. (Parameter 'source')'.It seems that Mapster does not apply null propagation automatically in such cases, even though the destination property is nullable.
Reproduction Steps
Expected Behavior
The mapping should return null for Destination.ProductNames when Source.Products is null, similar to AutoMapper's behavior. Null propagation should be applied by default, or at least be configurable.
Actual Behavior
System.ArgumentNullException: 'Value cannot be null. (Parameter 'source')'is thrown at runtime.Environment
Mapster version: 10.0.11