title: Why is Cosmos DB giving me an "The input name '{' is invalid" error when I call CreateItemAsync
body: <p>I am working on an ASP.Net Core 3.0 API with an Azure Cosmos DB as the persistence store. This is my first attempt at working with Cosmos DB. When I try to create a new item (document), I am getting back an error in Postman that says...</p>
  
  <pre><code>"Response status code does not indicate success: 400 Substatus: 0 
  Reason: (Message: {\"Errors\":[\"The input name '{' is invalid. 
  Ensure to provide a unique non-empty string less than '1024' characters."
  </code></pre>
  
  <p>I cannot figure out what is causing this problem.</p>
  
  <p>I am using the Microsoft.Azure.Cosmos v3.4.0 nuget in my project</p>
  
  <p>Here is the method in my repository for adding the new Account document.</p>
  
  <pre><code>public async Task AddAccountAsync(Account account)
  {
      await _container.CreateItemAsync(account, new PartitionKey(account.Id));
  }
  </code></pre>
  
  <p>Here is a pic of the property values when I hover over the "Account account" object while in debug mode. </p>
  
  <p><a href="https://i.stack.imgur.com/rJj2r.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rJj2r.png" alt="enter image description here"></a> </p>
  
  <p>My container in Cosmos DB is set up with /id as the partition key.</p>
  
  <p>Here is my request body in Postman;</p>
  
  <pre><code>{
    "id": "00000000-0000-0000-0000-000000000000",
    "accountName": "Test Company 1",
    "accountType": 1,
    "ownerId": "00000000-0000-0000-0000-000000000000",
    "isTaxExempt": false,
    "mailJobProxyId": "00000000-0000-0000-0000-000000000000",
    "salesPersonId": "00000000-0000-0000-0000-000000000000"
  </code></pre>
  
  <p>}</p>
  
  <p>Here is the Account class;</p>
  
  <pre><code>public class Account
  {
  
      // Aggregate state properties
      [JsonProperty(PropertyName = "id")]
      public AccountId Id { get; set; }
  
      [JsonProperty(PropertyName = "accountName")]
      public AccountName AccountName { get; set; }
  
      [JsonProperty(PropertyName = "accountType")]
      public AccountTypes AccountType { get; set; }
  
      [JsonProperty(PropertyName = "ownerId")]
      public OwnerId OwnerId { get; set; }
  
      [JsonProperty(PropertyName = "isTaxExempt")]
      public bool IsTaxExempt { get; set; }
  
      [JsonProperty(PropertyName = "mailJobProxyId")]
      public MailJobProxyId MailJobProxyId { get; set; }
  
      [JsonProperty(PropertyName = "salesPersonId")]
      public SalesPersonId SalesPersonId { get; set; }
  
      [JsonProperty(PropertyName = "addresses")]
      public List&lt;Address.Address&gt; Addresses { get; set; }
  
      [JsonProperty(PropertyName = "contacts")]
      public List&lt;Contact.Contact&gt; Contacts { get; set; }
  
      [JsonProperty(PropertyName = "postagePaymentMethods")]
      public List&lt;PostagePaymentMethod.PostagePaymentMethod&gt; PostagePaymentMethods { get; set; }
  
      public Account(string id, string accountName, AccountTypes accountType, string ownerId, Guid mailJobProxyId, Guid salesPersonId, bool isTaxExempt)
      {
          Id = AccountId.FromString(id);
          AccountName = AccountName.FromString(accountName);
          AccountType = accountType;
          OwnerId = OwnerId.FromString(ownerId);
          MailJobProxyId = new MailJobProxyId(mailJobProxyId);
          SalesPersonId = new SalesPersonId(salesPersonId);
          IsTaxExempt = isTaxExempt;
          Addresses = new List&lt;Address.Address&gt;();
          Contacts = new List&lt;Contact.Contact&gt;();
          PostagePaymentMethods = new List&lt;PostagePaymentMethod.PostagePaymentMethod&gt;();
          Status = Status.Active;
  
      }
  }
  </code></pre>
  
  <p>Please let me know if you need other code examples.</p>
  
  <p><strong>UPDATE 11/6/19 at 6:43p EST</strong></p>
  
  <p>Here is the AccountId value object</p>
  
  <pre><code>   public class AccountId : Value&lt;AccountId&gt;
      {
          public string Value { get; internal set; }
  
          // Parameterless constructor for serialization requirements
          protected AccountId() { }
  
          internal AccountId(string value) =&gt; Value = value;
  
          // Factory pattern
          public static AccountId FromString(string accountId)
          {
              CheckValidity(accountId);
              return new AccountId(accountId);
          }
  
          public static implicit operator string(AccountId accountId) =&gt; accountId.Value;
  
          private static void CheckValidity(string value)
          {
              if (!Guid.TryParse(value, out _))
              {
                  throw new ArgumentException(nameof(value), "Account Id is not a GUID.");
              }
          }
      }
  </code></pre>
  
  <p>And here is the initialization class in Startup.cs that sets up the database and container.</p>
  
  <pre><code>private static async Task&lt;AccountsRepository&gt; InitializeCosmosClientAccountInstanceAsync(IConfigurationSection configurationSection)
  {
      var databaseName = configurationSection.GetSection("DatabaseName").Value;
      string uri = configurationSection.GetSection("Uri").Value;
      string key = configurationSection.GetSection("Key").Value;
      CosmosClientBuilder clientBuilder = new CosmosClientBuilder(uri, key);
      CosmosClient client = clientBuilder
                          .WithConnectionModeDirect()
                          .Build();
      DatabaseResponse database = await client.CreateDatabaseIfNotExistsAsync(databaseName);
  
      string containerName = configurationSection.GetSection("AccountsContainerName").Value;
      await database.Database.CreateContainerIfNotExistsAsync(containerName, "/id");
      AccountsRepository cosmosDbService = new AccountsRepository(client, databaseName, containerName);
  
      return cosmosDbService;
  } 
  </code></pre>
  
  <p>Here is the stack trace from when the error occurs;</p>
  
  <pre><code>stackTrace": "   at Microsoft.Azure.Cosmos.ResponseMessage.EnsureSuccessStatusCode()\r\n
  at Microsoft.Azure.Cosmos.CosmosResponseFactory.ToObjectInternal[T]
  (ResponseMessage cosmosResponseMessage, CosmosSerializer jsonSerializer)\r\n
  at Microsoft.Azure.Cosmos.CosmosResponseFactory. 
  &lt;CreateItemResponseAsync&gt;b__6_0[T](ResponseMessage cosmosResponseMessage)\r\n
  at Microsoft.Azure.Cosmos.CosmosResponseFactory.ProcessMessageAsync[T]
  (Task`1 cosmosResponseTask, Func`2 createResponse)\r\n   at
  Delivery.Api.Infrastructure.AccountsRepository.AddAccountAsync(Account
  account) in 
  C:\\AzureDevOps\\Delivery\\Delivery.Api\\Accounts\\AccountsRepository.cs:line 20\r\n 
  at Delivery.Api.Accounts.AccountsApplicationService.HandleCreate(Create cmd) 
  in C:\\AzureDevOps\\Delivery\\Delivery.Api\\Accounts\\AccountsApplicationService.cs:line 43\r\n 
  at Delivery.Api.Infrastructure.RequestHandler.HandleCommand[T](T request, Func`2 handler, ILogger log) 
  in C:\\AzureDevOps\\Delivery\\Delivery.Api\\Infrastructure\\RequestHandler.cs:line 16
  </code></pre>