title: Reset Json.NET Contract-Cache
body: <p>I am using a custom Json.NET contract resolver in my project which adds some more properties to the contract model.</p>
  
  <pre class="lang-cs prettyprint-override"><code>protected override JsonObjectContract CreateObjectContract(Type objectType)
  {
      var contract = base.CreateObjectContract(objectType);
      AddSomeMorePropertiesToContract(contract, objectType);
  
      return contract;
  }
  </code></pre>
  
  <p>During the lifetime of the application this custom property-list of my models can change, some of the properties might be removed and some might be added. </p>
  
  <p>However Json.NET resolves the <code>JsonObjectContracts</code> and its properties only <em>once</em> when the type is used for the first time and caches it, so the the new properties-list is never applied!</p>
  
  <p><strong>Is there a way to tell Json.NET that it should reset its cache and resolve the contracts again?</strong></p>
  
  <hr>
  
  <p>The only workaround I found to achieve this is to store all contracts after they have been created and manually manipulate their properties when I want to update them:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class MyContractResolver : CamelCasePropertyNamesContractResolver
  {
      private static List&lt;JsonObjectContract&gt; OldContracts { get; } = new List&lt;JsonObjectContract&gt;();
  
      protected override JsonContract CreateContract(Type type)
      {
          var contract = base.CreateContract(type);
          OldContracts.Add((JsonObjectContract)contract);
  
          return contract;
      }
  
      public void UpdateContracts()
      {
          foreach (var oldContract in OldContracts)
          {
              oldContract.Properties.Clear();
              var newContract = (JsonObjectContract)base.CreateContract(oldContract.UnderlyingType);
              oldContract.Properties.AddRange(newContract.Properties);
          }
      }
  </code></pre>
  
  <p>This works, but instead of manually updating the properties, I would much prefere to only somehow reset the cache and let Json.NET resolve the contracts again on its own.</p>