title: Confusion about CreateItemAsync and new PartitionKey in Azure Cosmos DB - .NET Core
body: <p>I am trying to setup a simple console project with Azure Cosmos DB. I am confused about the Partition Key Usage.</p>
  <p>Note, I have already looked at this solution, but I believe I have a slightly different situation.</p>
  <ul>
  <li><a href="https://stackoverflow.com/questions/58121736/partitionkey-extracted-from-document-doesnt-match-the-one-specified-in-the-head">PartitionKey extracted from document doesn&#39;t match the one specified in the header on CreateItemAsync</a></li>
  </ul>
  <p>I am setting up the container like this.</p>
  <pre><code>private string PartitionKeyPath = &quot;/ProductPartitionKey&quot;;
  this.container = await this.database.CreateContainerIfNotExistsAsync(containerId, PartitionKeyPath);
  </code></pre>
  <p>Here is an example JSON, as it gets stored in the container. So, I am successful in getting items added.</p>
  <pre><code>{
      &quot;Name&quot;: &quot;Super Curtain&quot;,
      &quot;UnitPrice&quot;: 500,
      &quot;id&quot;: &quot;124BBC08-F51C-4ED4-B961-8DD0C966F66F&quot;,
      &quot;ProductPartitionKey&quot;: &quot;Hello&quot;,
      &quot;_rid&quot;: &quot;m2VTANekt8ACAAAAAAAAAA==&quot;,
      &quot;_self&quot;: &quot;dbs/m2VTAA==/colls/m2VTANekt8A=/docs/m2VTANekt8ACAAAAAAAAAA==/&quot;,
      &quot;_etag&quot;: &quot;\&quot;0500753f-0000-1800-0000-5f735ac70000\&quot;&quot;,
      &quot;_attachments&quot;: &quot;attachments/&quot;,
      &quot;_ts&quot;: 1601395399
  }
  </code></pre>
  <p>I am able to do an insert with both the following lines of usage.</p>
  <pre><code>var tempPartitionKey = new PartitionKey(tempProduct.ProductPartitionKey);
  
  ItemResponse &lt; Product &gt; tempProductResponse = await this.container.CreateItemAsync &lt; Product &gt; (tempProduct, tempPartitionKey);
  ItemResponse &lt; Product &gt; tempProductResponse = await this.container.CreateItemAsync &lt; Product &gt; (tempProduct);
  </code></pre>
  <p>The issue is, why wont the following work?</p>
  <pre><code>var tempPartitionKey2 = new PartitionKey(&quot;/ProductPartitionKey&quot;);
  ItemResponse &lt; Product &gt; tempProductResponse = await this.container.CreateItemAsync &lt; Product &gt; (tempProduct, tempPartitionKey2);
  </code></pre>
  <p>or this.</p>
  <pre><code>var tempPartitionKey3 = new PartitionKey(&quot;ProductPartitionKey&quot;);
  ItemResponse&lt;Product&gt; tempProductResponse = await this.container.CreateItemAsync&lt;Product&gt;(tempProduct, tempPartitionKey3);
  </code></pre>
  <p>I get the same error in the linked stack question.</p>
  <pre><code>PartitionKey extracted from document doesn't match the one specified in the header
  </code></pre>
  <p><em>so, ultimately, I am trying to understand, what string literal can I use, with new PartitionKey()?</em></p>
  <p>Or,</p>
  <p><em>is it so that, at current point of time, this is the only way to set and use Partition Key and I should not be trying to set the Partition Key with direct, string literal values? Perhaps, it is not a good way to do this, and azure cosmos library has stopped or removed that ability.</em></p>