Skip to content

Mapping to Enumerable.Empty<T> throws in netcoreapp3.1 #3365

@natehitze

Description

@natehitze

I believe it is related to this issue: dotnet/runtime#27552

public class SourceClass
{
    public IEnumerable<string> Values { get; set; }
}
public class TargetClass
{
    public IEnumerable<string> Values { get; set; }
}
var config = new MapperConfiguration(cfg => cfg.CreateMap<SourceClass, TargetClass>());
var mapper = new Mapper(config);
var source = new SourceClass { Values = new string[0] };
var existingTarget = new TargetClass { Values = Enumerable.Empty<string>() };
// This line throws in netcoreapp3.1 but not in netcoreapp2.2
mapper.Map(source, existingTarget);

Expected behavior

Not to throw an exception.

Actual behavior

Unable to cast object of type 'System.Linq.EmptyPartition`1[System.String]' to type 'System.Collections.Generic.IList`1[System.String]'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions