title: Using AutoMapper to map unknown types
body: <p>I'm using <code>AutoMapper</code> to copy the properties of one object to another: This is my code:</p>
  
  <pre><code>// Get type and create first object
  Type itemType = Type.GetType(itemTypeName);
  var item = Activator.CreateInstance(itemType);
  
  // Set item properties
  .. Code removed for clarity ..
  
  // Get item from Entity Framework DbContext
  var set = dataContext.Set(itemType);
  var itemInDatabase = set.Find(id);
  if (itemInDatabase == null)
  {
      itemInDatabase = Activator.CreateInstance(itemType);
      set.Add(itemInDatabase);
  }
  
  // Copy item to itemInDatabase
  Mapper.CreateMap(itemType, itemType);
  Mapper.Map(item, itemInDatabase);
  
  // Save changes
  dataContext.SaveChanges();
  </code></pre>
  
  <p>The problem is that <code>Mapper.Map()</code> throws an <code>AutoMapperMappingException</code>:</p>
  
  <pre><code>Missing type map configuration or unsupported mapping.
  
  Mapping types:
  Object -&gt; MachineDataModel
  System.Object -&gt; MyProject.DataModels.MachineDataModel
  
  Destination path:
  MachineDataModel
  
  Source value:
  MyProject.DataModels.MachineDataModel
  </code></pre>
  
  <p>I don't really understand what the problem is, and what can I do to fix it?</p>