title: Trying to use a custom resolver in AutoMapper, which throws Object Ref Error
body: <p>I have received an error </p>
  
  <blockquote>
    <p>{"Object reference not set to an instance of an object."} </p>
  </blockquote>
  
  <p>when trying to use a custom resolver (to force any Null returns to use a default set of values) like so :</p>
  
  <pre><code>public class AnswersResolver : IValueResolver&lt;SurveyMonkey.Containers.Question, Question, QuestionAnswers&gt;
  {
      public QuestionAnswers Resolve(SurveyMonkey.Containers.Question source, Question destination, QuestionAnswers destMember, ResolutionContext context)
      {
          if (source.Answers != null)
          {
              QuestionAnswers q = Mapper.Map&lt;QuestionAnswers&gt;(source.Answers);
              return q;
          }
          else
          {
              QuestionAnswers q = new QuestionAnswers
              {
                  Id = source.Id * 100000,
                  Choices = {},
                  Cols = { new Column {  Choices = {  } } },
                  Other = new OtherAnswer { Text = "NO ANSWER" },
                  Rows = { new Row {  Text = "NO ANSWER" } }
              };
              Choice c = new Choice { Description = "No ANSWER REQUIRED", Position = 0, Items = { }, QuestionAnswersId = q.Id.GetValueOrDefault(), QuestionAnswers = q };
              q.Choices.Add(c);
              q.Cols[0].Choices.Add(c);
              q.Cols[0].QuestionAnswers = q;
              q.Cols[0].QuestionAnswersId = q.Id.GetValueOrDefault();
              q.Rows[0].QuestionAnswers = q;
              q.Rows[0].QuestionAnswersId = q.Id.GetValueOrDefault();
              return q;
          }
      }
  }
  </code></pre>
  
  <p>When I put in a break point I successfully cycle through several iterations, and the error is thrown at the Automapper.map command for Survey - which contains Question and contains  Page which contains (some of) the same Question Objects.</p>
  
  <p>EDIT: Error Message as requested</p>
  
  <blockquote>
    <p>AutoMapper.AutoMapperMappingException was unhandled
       HResult=-2146233088
       Message=Error mapping types.</p>
    
    <p>Mapping types:
       Survey -> Survey
       SurveyMonkey.Containers.Survey -> SurveyMonkeyAPIv3.Survey</p>
    
    <p>Type Map configuration:
       Survey -> Survey
       SurveyMonkey.Containers.Survey -> SurveyMonkeyAPIv3.Survey</p>
    
    <p>Property:
       Questions
         Source=Anonymously Hosted DynamicMethods Assembly
         StackTrace:
            at lambda_method(Closure , Object , Object , ResolutionContext )
            at SurveyMonkeyAPIv3.Program.DefinedSurveyCalls(SurveyContext Survey, String APIKey, String Token, Int64[] ValidSurveys) in C:\Surveymonkeytake2\SurveyMonkeyAPIv3\Program.cs:line 77
            at SurveyMonkeyAPIv3.Program.Main(String[] args) in C:\Surveymonkeytake2\SurveyMonkeyAPIv3\Program.cs:line 41
            at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
            at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
            at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
            at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
            at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
            at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
            at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
            at System.Threading.ThreadHelper.ThreadStart()
       InnerException: 
            HResult=-2146233088
            Message=Error mapping types.</p>
    
    <p>Mapping types:
       Question -> Question
       SurveyMonkey.Containers.Question -> SurveyMonkeyAPIv3.Question</p>
    
    <p>Type Map configuration:
       Question -> Question
       SurveyMonkey.Containers.Question -> SurveyMonkeyAPIv3.Question</p>
    
    <p>Property:
       Answers
          Source=Anonymously Hosted DynamicMethods Assembly
          StackTrace:
               at lambda_method(Closure , Object , Object , ResolutionContext )
          InnerException: 
               HResult=-2147467261
               Message=Object reference not set to an instance of an object.
               Source=SurveyMonkeyAPIv3
               StackTrace:
                    at SurveyMonkeyAPIv3.AnswersResolver.Resolve(Question source, Question destination, QuestionAnswers destMember, ResolutionContext context) in C:\Surveymonkeytake2\SurveyMonkeyAPIv3\Program.cs:line 854
                    at lambda_method(Closure , Object , Object , ResolutionContext )
               InnerException: </p>
  </blockquote>
  
  <p>There is no text after that last inner exception</p>