Sequence contains no elements...

33 views
Skip to first unread message

Keith Barrows

unread,
May 2, 2016, 3:28:57 PM5/2/16
to AutoMapper-users
Source class:
public class IndexWorkSessionModel
{
    public int Id { get; set; }
    public string GlobalPartNumber { get; set; }
    public int Status { get; set; }
    public DateTime CreatedDate { get; set; }
}

Target class:
public class IndexWorkSessionViewModel : IndexWorkSessionModel
{
        private SessionStatuses StatusEnum => (SessionStatuses)Status;
        public string StatusDisplay => StatusEnum.ToDisplay();
}

Mapper:
internal class MappingProfileProductReuse : MappingProfileBase
{
    protected override void Configure()
    {

        CreateMap<IndexWorkSessionViewModel, ServiceModels.IndexWorkSessionModel>()
            .IgnoreAllPropertiesWithAnInaccessibleSetter()
            .IgnoreAllSourcePropertiesWithAnInaccessibleSetter()
            .ReverseMap();
        
        // other mappings....
    }
}

I really expected this to "just work".  For some reason, the mapper is throwing the error (Sequence contains no elements) and I am not seeing anything obvious.

Thoughts?

Keith Barrows

unread,
May 2, 2016, 3:47:28 PM5/2/16
to AutoMapper-users
Found the culprit.  If you take out .IgnoreAllSourcePropertiesWithAnInaccessibleSetter() it runs with no errors.

I don't understand why this error is popping up.  If I understand these 2 methods, the 2nd one should have found public string StatusDisplay => StatusEnum.ToDisplay(); which has a private (non-existent) setter.

Can anyone enlighten me here?  :)

-kb
Reply all
Reply to author
Forward
0 new messages