title: C# AutoMapperMappingException KeyNotFoundException
body: <p><strong>I am guessing all the info except the exception is extra and barely relevant (and is here for completeness). The question is: What, exactly, is the problem that was encountered based on the exception below?</strong> </p>
  
  <p>I am having trouble understanding an exception message. To the best of my understanding, there was an error mapping <code>BsonDocument</code> to <code>ChildItemViewModel</code>. <code>Id</code>, <code>Description</code>, and <code>SequentialOrgId</code> were mapped successfully...and then something happened, though these are the only properties. Seems like it's looking for <code>_id</code> (a property that doesn't exist) in <code>cI</code> (BsonDocument that is being converted to ChildItemViewModel), but I have no idea if that's correct, because it makes no sense. </p>
  
  <p>This is a snippet of code (the mapping) where I BELIEVE this to be happening, but I have no idea since I don't have line numbers.</p>
  
  <pre><code>        foreach (BsonDocument cI in childItems)
          {
              ChildItemViewModel childItem = Mapper.Map&lt;BsonDocument, ChildItemViewModel&gt;(cI);
              itemView.ChildItems.Add(childItem);
          }
  </code></pre>
  
  <p>This is the Entity Framework View Model (class):</p>
  
  <pre><code>public class ChildItemViewModel
  {
      public long Id { get; set; }
      public string Description { get; set; }
      public long SequentialOrgId { get; set; }
  }
  </code></pre>
  
  <p>This is the source:</p>
  
  <p><a href="https://i.stack.imgur.com/N7je4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/N7je4.png" alt="enter image description here"></a></p>
  
  <p>Edit: I have confirmed the ChildItems field to be the source of the problem. If I clear them with the code below, the problem goes away:</p>
  
  <pre><code>db.items.update(
     { _id: 1245846 },
     { $set:
        {
              "ChildItems":[], 
              "ChildItemsAmount": NumberInt(0)
        }
     }
  )
  </code></pre>
  
  <p>The exception:   </p>
  
  <pre><code> {"message":"AutoMapper.AutoMapperMappingException: 
  
   Mapping types:
   BsonDocument -&gt; Int64
   MongoDB.Bson.BsonDocument -&gt; System.Int64
  
   Destination path:
   ChildItemViewModel.Id.Id
  
   Source value:
   { \"Id\" : NumberLong(1245854), \"Description\" : \"Image of Ext USB drive containing backup files labeled \\\"Kevin SomeLastName Backups\\\"\", \"SequentialOrgId\" : NumberLong(189) } ---&gt; System.Collections.Generic.KeyNotFoundException: Element '_id' not found.
      at MongoDB.Bson.BsonDocument.get_Item(String name)
      at lambda_method(Closure , BsonDocument )
      at AutoMapper.Internal.DelegateBasedResolver`2.Resolve(ResolutionResult source)
      at AutoMapper.NullReferenceExceptionSwallowingResolver.Resolve(ResolutionResult source)
      at System.Linq.Enumerable.Aggregate[TSource,TAccumulate](IEnumerable`1 source, TAccumulate seed, Func`3 func)
      at AutoMapper.Mappers.TypeMapObjectMapperRegistry.PropertyMapMappingStrategy.MapPropertyValue(ResolutionContext context, IMappingEngineRunner mapper, Object mappedObject, PropertyMap propertyMap)
      --- End of inner exception stack trace ---
      at AutoMapper.Mappers.TypeMapObjectMapperRegistry.PropertyMapMappingStrategy.MapPropertyValue(ResolutionContext context, IMappingEngineRunner mapper, Object mappedObject, PropertyMap propertyMap)
      at AutoMapper.Mappers.TypeMapObjectMapperRegistry.PropertyMapMappingStrategy.Map(ResolutionContext context, IMappingEngineRunner mapper)
      at AutoMapper.MappingEngine.AutoMapper.IMappingEngineRunner.Map(ResolutionContext context)
      at AutoMapper.MappingEngine.Map[TSource,TDestination](TSource source)
      at API.Classes.Automapper.ItemViewModelConverter.Convert(ResolutionContext resolution)
      at AutoMapper.Internal.MappingExpression`2.&lt;&gt;c__DisplayClass51_0.&lt;ConvertUsing&gt;b__0(ResolutionContext context)
      at AutoMapper.MappingEngine.AutoMapper.IMappingEngineRunner.Map(ResolutionContext context)
      at AutoMapper.MappingEngine.Map[TSource,TDestination](TSource source)
      at MongoDB.Bson.Serialization.Serializers.ProjectingDeserializer`2.Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
      at MongoDB.Bson.Serialization.IBsonSerializerExtensions.Deserialize[TValue](IBsonSerializer`1 serializer, BsonDeserializationContext context)
      at MongoDB.Driver.Core.WireProtocol.Messages.Encoders.BinaryEncoders.ReplyMessageBinaryEncoder`1.ReadMessage()
      at MongoDB.Driver.Core.Connections.BinaryConnection.&lt;ReceiveMessageAsync&gt;d__15.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at MongoDB.Driver.Core.WireProtocol.QueryWireProtocol`1.&lt;ExecuteAsync&gt;d__0.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at MongoDB.Driver.Core.Servers.ClusterableServer.ServerChannel.&lt;ExecuteProtocolAsync&gt;d__24`1.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at MongoDB.Driver.Core.Operations.FindOperation`1.&lt;ExecuteAsync&gt;d__2.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at MongoDB.Driver.OperationExecutor.&lt;ExecuteReadOperationAsync&gt;d__0`1.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at MongoDB.Driver.MongoCollectionImpl`1.&lt;ExecuteReadOperation&gt;d__35`1.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at MongoDB.Driver.IFindFluentExtensions.&lt;SingleOrDefaultAsync&gt;d__f`2.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at API.Controllers.ItemsController.&lt;GetItem&gt;d__2.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at System.Threading.Tasks.TaskHelpersExtensions.&lt;CastToObject&gt;d__3`1.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at System.Web.Http.Controllers.ApiControllerActionInvoker.&lt;InvokeActionAsyncCore&gt;d__0.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at System.Web.Http.Filters.ActionFilterAttribute.&lt;CallOnActionExecutedAsync&gt;d__5.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Web.Http.Filters.ActionFilterAttribute.&lt;CallOnActionExecutedAsync&gt;d__5.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at System.Web.Http.Filters.ActionFilterAttribute.&lt;ExecuteActionFilterAsyncCore&gt;d__0.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at System.Web.Http.Filters.ActionFilterAttribute.&lt;CallOnActionExecutedAsync&gt;d__5.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Web.Http.Filters.ActionFilterAttribute.&lt;CallOnActionExecutedAsync&gt;d__5.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at System.Web.Http.Filters.ActionFilterAttribute.&lt;ExecuteActionFilterAsyncCore&gt;d__0.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at System.Web.Http.Filters.ActionFilterAttribute.&lt;CallOnActionExecutedAsync&gt;d__5.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Web.Http.Filters.ActionFilterAttribute.&lt;CallOnActionExecutedAsync&gt;d__5.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at System.Web.Http.Filters.ActionFilterAttribute.&lt;ExecuteActionFilterAsyncCore&gt;d__0.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at System.Web.Http.Filters.ActionFilterAttribute.&lt;CallOnActionExecutedAsync&gt;d__5.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Web.Http.Filters.ActionFilterAttribute.&lt;CallOnActionExecutedAsync&gt;d__5.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at System.Web.Http.Filters.ActionFilterAttribute.&lt;ExecuteActionFilterAsyncCore&gt;d__0.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at System.Web.Http.Controllers.ActionFilterResult.&lt;ExecuteAsync&gt;d__2.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at System.Web.Http.Filters.AuthorizationFilterAttribute.&lt;ExecuteAuthorizationFilterAsyncCore&gt;d__2.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at System.Web.Http.Controllers.AuthenticationFilterResult.&lt;ExecuteAsync&gt;d__0.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      at System.Web.Http.Controllers.ExceptionFilterResult.&lt;ExecuteAsync&gt;d__0.MoveNext()"}
  </code></pre>