title: WCF returns ArrayOfKeyValueOfintstringKeyValueOfintstring[] instead of Dictionary<int, string> and Array instread of List
body: <p>So I've spent the last several hours investigating this issue and it is clear that I am not the only one. Why are my Dictionaries and Lists being returned as Arrays? </p>
  
  <p>I understand that Arrays are used as default for the sake of compatibility. WCF makes a conscious effort to distance itself from being .Net dependent. But both my Server and Client are developed in C# .Net so I'm okay.</p>
  
  <p>Here is a sampling of similar questions on just StackOverflow alone:</p>
  
  <ol>
  <li><a href="https://stackoverflow.com/questions/13551541/wcf-service-returning-array-instead-of-list">WCF service returning array instead of List</a>   </li>
  <li><a href="https://stackoverflow.com/questions/493376/why-does-wcf-return-myobject-instead-of-listt-like-i-was-expecting">Why does WCF return myObject[] instead of List like I was
  expecting?</a>    </li>
  <li><a href="https://stackoverflow.com/questions/2160052/wcf-service-returning-an-array-of-dictionarystring-object">WCF service returning an array of dictionary</a>    </li>
  <li><a href="https://stackoverflow.com/questions/13513027/wcf-proxy-returning-array-instead-of-list-even-though-collection-type-generic">WCF Proxy Returning Array instead of List EVEN THOUGH Collection
  Type == Generic.List</a>    </li>
  <li><a href="https://stackoverflow.com/questions/13298066/wcf-returning-array-instead-of-list-even-though-collection-type-generic-list">WCF Returning Array instead of List EVEN THOUGH Collection Type ==
  Generic.List</a>    </li>
  <li><a href="https://stackoverflow.com/questions/2525463/why-does-my-wcf-service-return-and-array-instead-of-a-list-t">Why does my WCF service return and ARRAY instead of a List ?</a>    </li>
  <li><a href="https://stackoverflow.com/questions/14101245/array-instead-of-list-in-wcf-service-proxy-generated-using-svcutil-exe">Array instead of List in WCF Service Proxy Generated using
  svcutil.exe</a></li>
  </ol>
  
  <p><strong>What I have set up:</strong>
  <img src="https://i.stack.imgur.com/Dpcat.jpg" alt="Service Reference Configuration"></p>
  
  <p>I am generating the Proxy via this command: </p>
  
  <pre><code> C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin&gt;svcutil.exe /language:cs
   /out:generatedProxy.cs /config:app.config /ct:System.Collections.Generic.List`1
    http://192.168.0.99:9000/ProjectDatabase/??
  </code></pre>
  
  <p>My service contract looks like this:</p>
  
  <pre><code>[ServiceContract]
  public interface IMyContract
  {
      [OperationContract]
      [ServiceKnownType(typeof(Dictionary&lt;int, string&gt;))]
      Dictionary&lt;int, string&gt; getClassDictionary();
  }
  </code></pre>
  
  <p>My implementation:</p>
  
  <pre><code>public Dictionary &lt;int, string&gt; getClassDictionary()
  {
     Dictionary&lt;int, string&gt; myDict = new Dictionary&lt;int, string&gt;();
     myDict.Add(1, "Geometry");
     myDict.Add(2, "Algebra");
     myDict.Add(3, "Graph Theory");
     return myDict; 
  }
  </code></pre>
  
  <p>Even in my <code>Reference.svcmap</code> I have:</p>
  
  <pre><code>&lt;CollectionMappings&gt;
    &lt;CollectionMapping TypeName="System.Collections.Generic.List`1" Category="List" /&gt;
  &lt;/CollectionMappings&gt;
  </code></pre>
  
  <p>However, despite my best efforts and research I still get:</p>
  
  <blockquote>
    <p>Dictionary&lt;'int, string'> returning as ArrayOfKeyValueOfintstringKeyValueOfintstring[]</p>
  </blockquote>
  
  <p>And:</p>
  
  <blockquote>
    <p>List&lt;'T'> returning as T[]</p>
  </blockquote>
  
  <p>I feel like I've tried everything and done everything right, but I have to be missing something. So what is it? Thank you for your time, help, and consideration. </p>
  
  <p><strong>Update:</strong></p>
  
  <p>I've even attempted a route of working around the <code>Array</code> imposition, by writing a <code>serializable</code> <code>struct</code> and adding them to an array. </p>
  
  <pre><code>[Serializable]
  public struct KeyValuePair&lt;K, V&gt;
  {
      public K Key { get; set; }
      public V Value { get; set; }
  }
  </code></pre>
  
  <p>However, when I return the <code>KeyValuePair&lt;int, string&gt;[]</code>. My proxy is generating a return of <code>KeyValuePairOfintstring[]</code>.</p>
  
  <p><strong>Solution is posted below.</strong></p>