tags:

views:

32

answers:

1

I'm starting to learn AutoMapper and coming up against a couple of minor problems.

Essentially I'm getting null reference exceptions when trying to bind to ILists produced by AutoMapper.

My boot strapping method looks like this:

Mapper.CreateMap<Claimant, ClaimantViewModel>()
                .ForMember(
                        vm => vm.Check, 
                        opt => opt.Ignore());

Mapper.CreateMap<IList<Claimant>, IList<ClaimantViewModel>>();
Mapper.AssertConfigurationIsValid();

Which doesn't look to fancy to me. I then try to call:

dlWAMs.DataSource = Mapper.Map<IList<Claimant>, IList<ClaimantViewModel>(someilist);
dlWAMs.DataBind();

With that I'm getting a null reference exception. If I code my own loop and map the models to a view model one at a time the code runs fine.

What am I doing wrong?

+1  A: 

First of all you don't need that second map that creates map from IList to IList, remove it. Than if it does not work, show us your classes.

epitka

related questions