title: Error "The given key was not present in the dictionary" When Creating New Custom Entity on Update Event
body: <p>On CRM 2013 on-premise, I'm trying to write a plugin that triggers when an update is made to a field on Quote. The plugin then creates a new custom entity "new_contract".</p>
  
  <p>My plugin is successfully triggered when the update to that field is made. However I keep getting an error message "The given key was not present in the dictionary" when trying to create the new custom entity.</p>
  
  <p>I'm using a "PostImage" in this code. I confirm that it's registered using the same name in Plugin Registration. </p>
  
  <p>Here is the code</p>
  
  <pre><code>var targetEntity = context.GetParameterCollection&lt;Entity&gt;
                     (context.InputParameters, "Target");
  if (targetEntity == null)
    {throw new InvalidPluginExecutionException(OperationStatus.Failed, 
              "Target Entity cannot be null")}
  var postImage = context.PostEntityImages["PostImage"];
  if (postImage == null)
    {throw new InvalidPluginExecutionException(OperationStatus.Failed, 
              "Post Image is required");}
  
  var quote = context.GenerateCompositeEntity(targetEntity, postImage);
  //throw new InvalidPluginExecutionException(OperationStatus.Failed, "Update is captured");
  //Guid QuoteId = (Guid)quote.Attributes["quoteid"];
  var serviceFactory = (IOrganizationServiceFactory)serviceProvider
                         .GetService(typeof(IOrganizationServiceFactory));
  var service = serviceFactory.CreateOrganizationService(context.UserId);
  
  var contractEntity = new Entity();
  contractEntity = new Entity("new_contract");
  if (quote.Attributes.Contains("portfolio"))
  {
    var quotePortfolio = (EntityReference)quote.Attributes["new_portfolio];
    contractEntity[Schema.new_contract.PortfolioName] = 
         new EntityReference(quotePortfolio.LogicalName, quotePortfolio.Id);
  }
  if (quote.Attributes.Contains(Schema.Quote.QuoteName))
  {
    var quoteName = (string)quote.Attributes["name"];
    contractEntity[Schema.new_contract.contractName] = quoteName;
  }
  var contractId = service.Create(contractEntity);
  </code></pre>