title: Using AutoMapper to dynamically map objects including arrays
body: <p>I'm trying to build a way of mapping from one type to another, knwoing they will (should) have the same structure. <a href="https://stackoverflow.com/questions/2622003/call-webservice-without-adding-a-webreference-with-complex-types">Related Question</a>.</p>
  
  <p>For ease of the fiddly bits, I'm using AutoMapper from Codeplex, with the following function:</p>
  
  <pre><code>private static List&lt;Type&gt; seenTypes = new List&lt;Type&gt;();
  
  private static void MapDataObjects(Type a, Type b)
  {
      AutoMapper.Mapper.CreateMap(a, b);
  
      PropertyInfo[] aProps = a.GetProperties();
      PropertyInfo[] bProps = b.GetProperties();
      foreach (PropertyInfo aProp in aProps)
      {
          if (aProp.PropertyType.Namespace.StartsWith("System") 
               || seenTypes.Contains(aProp.PropertyType))
              continue;
  
          foreach (PropertyInfo bProp in bProps)
          {
              if (aProp.Name == bProp.Name)
              {
                  MapDataObjects(aProp.PropertyType, bProp.PropertyType);
                  seenTypes.Add(aProp.PropertyType);
                  break;
              }
          }
      }
   }
  </code></pre>
  
  <p>Which appears to work fine when stepping through the code, however calling my Map function gives the following error:</p>
  
  <pre><code>AutoMapper.AutoMapperMappingException: 
       Trying to map TDXDataTypes.ClientActivity[] to ClientActivity[].
  Using mapping configuration for TDXDataTypes.ClientActivity[] to ClientActivity[]
  Destination property: Activities
  Exception of type 'AutoMapper.AutoMapperMappingException' was thrown. 
      ---&gt; System.ArgumentException: 
           Type 'ClientActivity[]' does not have a default constructor
  </code></pre>