title: Mapping from dynamic to type with property defined with interface type
body: <p>The context around this is that I'd like to map a <code>dynamic</code> dapper result to an object and that object has a property which has an interface type:</p>
  
  <pre><code>public class TargetModel
  {
      public int Id { get; set; }
      public IAddress AbstractAddress { get; set; }
  }
  </code></pre>
  
  <p>The dynamic to object bit is straight forward but I'm unable to configure AutoMapper to tell it how to handle the interface.</p>
  
  <pre><code>dynamic sourceModel = new ExpandoObject();
  
  // flat model - id should map to TargetModel, Address01 will map to a nested type Address on TargetModel
  sourceModel.Id = 1;
  sourceModel.Address01 = "address01";
  
  // for debugging purposes address maps ok from dynamic
  Address address = Mapper.Map&lt;Address&gt;(sourceModel);
  
  // this maps, but AbstractAddress is null - I need to config AutoMapper to understand how to map IAddress to Address
  TargetModel target = Mapper.Map&lt;TargetModel&gt;(sourceModel);
  </code></pre>
  
  <p>I've tried to tell it how to deal with the property:</p>
  
  <pre><code>CreateMap&lt;ExpandoObject, TargetModel&gt;()
      .ForMember(y =&gt; y.AbstractAddress, opts =&gt; opts.MapFrom(f =&gt; f));
  </code></pre>
  
  <p>Which fails with:</p>
  
  <blockquote>
    <p>System.ArgumentException: Cannot create an instance of interface type</p>
  </blockquote>
  
  <p>So I attempt to hint at the concrete:</p>
  
  <pre><code>CreateMap&lt;IAddress, Address&gt;().As&lt;Address&gt;();
  </code></pre>
  
  <p>Which doesn't resolve the issue and the exception remains.</p>
  
  <p>I've looked at the following questions/concepts and tried various configuration options but haven't been able to get the map working:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/40760779/automapper-mapping-objects-with-interface-properties">AutoMapper: Mapping objects with interface properties</a></li>
  <li><a href="https://dotnetfiddle.net/fPQxWx" rel="nofollow noreferrer">https://dotnetfiddle.net/fPQxWx</a></li>
  </ul>