title: How to implement an inherited Dictionary over WCF
body: <p>I’m trying to implement a dictionary for use with WCF.  My requirements are:</p>
  
  <ul>
  <li>actual (private variable or base
  class) type equivalent to
  Dictionary </li>
  <li>Comparer
  =  <code>System.StringComparer.InvariantCultureIgnoreCase</code></li>
  <li>Custom (override/new) Add(key,
  value) method (to include
  validations).  </li>
  <li>Override ToString()</li>
  <li>Use of the same type on both the client and host</li>
  </ul>
  
  <p>I’ve attempted using this class in a common project shared by the WCF host and client projects:</p>
  
  <pre><code>[Serializable]
  public class MyDictionary : Dictionary&lt;string, object&gt;
  {
    public MyDictionary()
      : base(System.StringComparer.InvariantCultureIgnoreCase)
    { }
  
    public new void Add(string key, object value)
    { /* blah */ }
  
    public override string ToString()
    { /* blah */ }
  }
  
  [DataContract]
  [KnownType(typeof(MyDictionary))]
  [KnownType(typeof(object[]))]
  [KnownType(typeof(double[]))]
  [KnownType(typeof(string[]))]
  [KnownType(typeof(DateTime[]))]
  public class ResultClass
  {
    public object Value{ get; set; }
    /* More properties */
  }
  public class ParmData
  {
    public object Value{ get; set; }
    /* More properties */
  }
  [DataContract]
  [KnownType(typeof(MyDictionary))]
  [KnownType(typeof(object[]))]
  [KnownType(typeof(double[]))]
  [KnownType(typeof(string[]))]
  [KnownType(typeof(DateTime[]))]
  public class ParameterClass
  {
    public List&lt;ParmData&gt; Data{ get; set; }
    /* More properties */
  }
  
  [OperationContract]
  ResultClass DoSomething(ParameterClass args);
  </code></pre>
  
  <p>Results:</p>
  
  <ul>
  <li>When I pass MyDictionary as one of the ParameterClass.Data.Value elements, I get a     missing KnownType exception.</li>
  <li>I can safely return MyDictionary in the ResultClass, but it is no longer my type.  It is just a Dictionary, and is not castable to <code>MyDictionary</code>.  Also comparer = <code>System.Collections.Generic.GenericEqualityComparer&lt;string&gt;</code>, not the case insensitive comparer I’m looking for.</li>
  </ul>
  
  <p>The help I’m asking for is to either fix my failed attempt, or a completely different way to achieve my stated requirements.  Any solution should not involve copying one dictionary to another.</p>
  
  <p>Thanks</p>