I have a nested collection in side an object:
public class Question
{
public AnswerObjectCollection Answers
{
get;
private set;
}
}
When I try to add answers to the AnswerObjectCollection
in the Question
object I get following exception:
Object reference not set to an instance of an object
Question currQuestion = new Question();
currQuestion.Answers.AddRange(GetAnswersByQuestion(currQuestion.QuestionIdentity));
If I try to create the answer object first (which does work) I can't add that either
AnswerObjectCollection answer = new AnswerObjectCollection();
answer.AddRange(GetAnswersByQuestion(currQuestion.QuestionIdentity));
currQuestion.Answers.AddRange(answer);
If I try mapping the objects I don't get an error but the currQuestion.Answers
variable is null
Mapper.CreateMap(typeof(AnswerObjectCollection), typeof(AnswerObjectCollection));
Mapper.CreateMap(typeof(Answer), typeof(Answer));
Mapper.Map(answer, currQuestion.Answers);