title: Using MappingEngine throws exception
body: <p>I'm maintaining an app which is using AutoMapper like this:</p>
  
  <pre><code>public class UserDomainService
  {
      public UserDTO GetUser(int id)
      { 
           Mapper.Reset();
           Mapper.CreateMap&lt;User, UserDTO&gt;();
           var user = ....;
           return Mapper.Map&lt;User, UserDTO&gt;(user);
      }
  }
  </code></pre>
  
  <p>This domain service is used by web-services.</p>
  
  <p>I think it can be a problem when two web-service requests come in and on separate threads Reset and Map are called. </p>
  
  <p>The Mapper can become in a state where the Map() fails.</p>
  
  <p>I know I should probably setup CreateMap() mappings in Application_Start, but for now I am trying to do this:</p>
  
  <pre><code>public class UserDomainService
  {
      public UserDTO GetUser(int id)
      { 
           var config = new AutoMapper.Configuration(new TypeMapFactory(), MapperRegistry.AllMappers());
           config.CreateMap&lt;User, UserDTO&gt;();
           var mapper = new MappingEngine(configuration);
           var user = ....;
           return mapper.Map&lt;User, UserDTO&gt;(user);
      }
  }
  </code></pre>
  
  <p>Leaving aside performance, is it anything which could potentially make the app crash?
  Sometimes I am getting an exception like this:</p>
  
  <pre><code>System.ArgumentException: An item with the same key has already been added.
     at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
     at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
     at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
     at AutoMapper.TypeMapFactory.GetTypeInfo(Type type)
     at AutoMapper.TypeMapFactory.CreateTypeMap(Type sourceType, Type destinationType, IMappingOptions options)
     at AutoMapper.Configuration.CreateTypeMap(Type source, Type destination, String profileName)
     at AutoMapper.Configuration.CreateMap[TSource,TDestination](String profileName)
     at AutoMapper.Configuration.CreateMap[TSource,TDestination]()
  </code></pre>
  
  <p>Note that the above sample mapping is just an example.</p>
  
  <p><strong>I am using AutoMapper v1.1.0.188 in a 3.5 Net app.</strong></p>
  
  <p><strong>EDIT:</strong>
  There's a specific reason why it's not easy for me to put the configuration in the Application_Start. 
  I have different mapping requirements depending on the context. For example, for the same User to UserDTO, I need two different types of mapping.</p>
  
  <p>It's the same problem described in this old question: </p>
  
  <p><a href="https://groups.google.com/forum/#!searchin/automapper-users/AM%2420per%2420request../automapper-users/5pfkZwSe0X0/99OuNoN8IOoJ" rel="nofollow">Link</a></p>