title: AutoMapper -- AutoMapperMappingException: Error mapping types
body: <p>I am getting this error:</p>
  
  <blockquote>
    <p>AutoMapperMappingException: Error mapping types.</p>
    
    <p>Mapping types: Game -> VirtualGame</p>
    
    <p>InvalidOperationException: Nullable object must have a value.</p>
    
    <p>Property: Timing lambda_method(Closure , object , object ,
    ResolutionContext )</p>
    
    <p>AutoMapperMappingException: Error mapping types.</p>
  </blockquote>
  
  <p>I think I've traced it down to the code block below.  Is there a way to check for null in this block so that this error goes away?</p>
  
  <pre><code>cfg.CreateMap&lt;Game, VirtualGame&gt;()
  
          .ForMember(d =&gt; d.GameTiming, opt =&gt;
                  {
  
                      opt.Condition(s =&gt; s.GameStartTime != null &amp;&amp; s.GameEndTime != null);
                      opt.MapFrom(
                          s =&gt; new Timing(s.GameStartTime.Value, s.GameEndTime.Value, s.GameDuration));
                  })
  </code></pre>
  
  <p>Oh, and this is what "Timing" is:</p>
  
  <pre><code>public Timing(DateTime gameStartTime, DateTime gameEndTime, Int32?
                gameDuration = null)
  </code></pre>