title: Json.NET fails to serialize dictionary of sets
body: <p>I'm trying to serialize (and later on deserialize) a <code>Dictionary&lt;string, ISet&lt;string&gt;&gt;</code>. Unfortunately, Json.NET (v6.0.3 via NuGet) fails to do this. What I do is</p>
  
  <pre><code>var value = new Dictionary&lt;string, ISet&lt;string&gt;&gt;
      {
          {"foo", new HashSet&lt;string&gt;{"bar"}}
      };
  var settings = new JsonSerializerSettings
      {
          TypeNameHandling = TypeNameHandling.Objects,
          TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple
      };
  var json = JsonConvert.SerializeObject(value, settings);
  </code></pre>
  
  <p>The variable <code>json</code> then holds the string</p>
  
  <pre><code>{"$type":"System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[System.Collections.Generic.ISet`1[[System.String, mscorlib]], System]], mscorlib","foo":["bar"]}
  </code></pre>
  
  <p>Now I want to deserialize the string with</p>
  
  <pre><code>JsonConvert.DeserializeObject&lt;IDictionary&lt;string, ISet&lt;string&gt;&gt;&gt;(json, settings);
  </code></pre>
  
  <p>which fails in resolving the Dictionary type, because it cannot find the <code>System</code> assembly that <code>ISet</code> belongs to. When I instead do the following</p>
  
  <pre><code>JsonConvert.DeserializeObject&lt;IDictionary&lt;string, ISet&lt;string&gt;&gt;&gt;(json);
  </code></pre>
  
  <p>everything works just fine. So it appears that the <code>TypeNameHandling</code> setting (changing/omitting the format does not change anything) actually breaks deserialization.</p>
  
  <p>I found that, if I don't set the <code>TypeNameHandling</code> settings, the serialized <code>$type</code> properties are simply ignored. I.e., when deserializing, the type information is taken solely from the target type where they are resolved. This works.</p>
  
  <p>When setting the <code>TypeNameHandling</code>, type resolution happens via reflection within the Json.NET assembly, which does not have a dependency on the <code>System</code> assembly and therefore fails to resolve the <code>ISet</code> interface. I can fix this by registering on <code>AppDomain.CurrentDomain.AssemblyResolve</code> and resolving the assembly like so</p>
  
  <pre><code>if (args.Name == "System")
  {
       return typeof (ISet&lt;&gt;).Assembly;
  }
  </code></pre>
  
  <p>but this seems very fragile to me, as it solves the problem for only this one specific assembly and I have to add another case for every assembly I need somewhere.</p>
  
  <p>Does anyone have experience on how to solve this? Any help is greatly appreciated!</p>