title: Is it OK to pass a generic Dictionary as a param to a method expecting IDictionary
body: <p>AssemblyInstaller.Install expects a System.Collections.IDictionary.</p>
  
  <p>Am I right to be 'allergic' to using non-generic collections such as Hashtable or should I get over myself?!</p>
  
  <p>e.g.</p>
  
  <pre><code>using System.Collections.Generic;
  using System.Configuration.Install;
  using System.Reflection;
  using AssemblyWithInstaller;
  
  namespace InstallerDemo
  {
      class InstallerDemo
      {
          static void Main(string[] args)
          {
              var savedState = new Dictionary&lt;object, object&gt;();
              // i.e. as opposed to something that implements IDictionary:
              //var savedState = new System.Collections.Hashtable()
              var assembly = Assembly.GetAssembly(typeof (MyInstaller));
              var ai = new AssemblyInstaller(assembly, new[] {"/LogFile=install.log"});
              ai.Install(savedState);
              ai.Commit(savedState);
          }
      }
  }
  </code></pre>
  
  <p>Additionally the compiler has no issue with this decalration:</p>
  
  <pre><code>var savedState = new Dictionary&lt;string, object&gt;();
  </code></pre>
  
  <p>But will anything bad happen at runtime if someone uses something other than strings as keys?</p>
  
  <hr>
  
  <p><strong>Update</strong> [Reflector to the rescue]</p>
  
  <pre><code>var savedState = new Dictionary&lt;string, object&gt;();
  </code></pre>
  
  <p>Confirming what Jon says, Dictionary implements IDictionary as follows:</p>
  
  <pre><code>void IDictionary.Add(object key, object value)
  {
      Dictionary&lt;TKey, TValue&gt;.VerifyKey(key);
      Dictionary&lt;TKey, TValue&gt;.VerifyValueType(value);
      this.Add((TKey) key, (TValue) value);
  }
  </code></pre>
  
  <p>...so in verifying the key it will throw an exception when the type of the key doesn't match that used when declaring the particular specialization of the generic Dictionary (and likewise for the type of the value):</p>
  
  <pre><code>private static void VerifyKey(object key)
  {
      if (key == null)
      {
          ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
      }
      if (!(key is TKey))
      {
          ThrowHelper.ThrowWrongKeyTypeArgumentException(key, typeof(TKey));
      }
  }
  </code></pre>