title: Problems with Json Serialize Dictionary<Enum, Int32>
body: <p>whenever i try to serialize the dictionary i get the exception:</p>
  
  <pre><code>System.ArgumentException: Type 
  'System.Collections.Generic.Dictionary`2[[Foo.DictionarySerializationTest+TestEnum, Foo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]'
  is not supported for serialization/deserialization of a dictionary,
  keys must be strings or object
  </code></pre>
  
  <p>My Testcase is:</p>
  
  <pre><code>public class DictionarySerializationTest
  {
    public enum TestEnum { A, B, C }
    //tried with numbers, too: public enum TestEnum { A = 1, B = 2, C = 3 }
  
    public void SerializationTest()
    {
      Dictionary&lt;TestEnum, Int32&gt; data = new Dictionary&lt;TestEnum, Int32&gt;();
  
      data.Add(TestEnum.A, 1);
      data.Add(TestEnum.B, 2);
      data.Add(TestEnum.C, 3);
  
      JavaScriptSerializer serializer = new JavaScriptSerializer();
      String result = serializer.Serialize(data);
      // Throws
    }
  
    public void SerializationToObjectTest()
    {
      Dictionary&lt;object, Int32&gt; data = new Dictionary&lt;object, Int32&gt;();
  
      data.Add(Enum.ToObject(typeof(TestEnum), TestEnum.A), 1);
      data.Add(Enum.ToObject(typeof(TestEnum), TestEnum.B), 2);
      data.Add(Enum.ToObject(typeof(TestEnum), TestEnum.C), 3);
  
      JavaScriptSerializer serializer = new JavaScriptSerializer();
      String result = serializer.Serialize(data);
      // Throws
    }
  
    public void SerializationStringTest()
    {
      Dictionary&lt;String, Int32&gt; data = new Dictionary&lt;String, Int32&gt;();
  
      data.Add(TestEnum.A.ToString(), 1);
      data.Add(TestEnum.B.ToString(), 2);
      data.Add(TestEnum.C.ToString(), 3);
  
      JavaScriptSerializer serializer = new JavaScriptSerializer();
      String result = serializer.Serialize(data);
      // Succeeds
    }
  
  }
  </code></pre>
  
  <p>Of course i could use .ToString() whenever i enter something into the Dictionary but since it's used quite often in performance relevant methods i would prefer using the enum.</p>
  
  <p>My only solution is using .ToString() and converting before entering the performance critical regions but that is clumsy and i would have to change my code structure just to be able to serialize the data.</p>
  
  <p>Does anyone have an idea how i could serialize the dictionary as <code>&lt;Enum, Int32&gt;</code>?</p>
  
  <p>I use the System.Web.Script.Serialization.JavaScriptSerializer for serialization.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I switched to <code>Dictionary&lt;String, Int32&gt;</code> now and it works but i hope someone shows a solution as i don't really like using strings in place of a type safe enum.</p>