title: Cannot apply indexing with [] to an expression of type 'object' (even though the type is 'dynamic')
body: <p>I have an <code>ExpandoObject</code> which is created like so:</p>
  
  <pre><code>public ExpandoObject Get()
  {
      var expando = new ExpandoObject();
      var expandoDic = (IDictionary&lt;string, dynamic&gt;)expando;
  
      // go through the items in the dictionary and copy over the key value pairs)
      foreach (var f in GetFieldList())
      {
          if (f.MaxValues == 1)
          {
              var val = f.Values.Count &gt; 0 ? f.Values[0] : null;
              if (f.displayType == DisplayType.Entity &amp;&amp; f.AttachedEntities != null &amp;&amp; f.AttachedEntities.Any())
              {
                  if (f.AttachedEntities.Count == 1)
                  {
                      expandoDic.Add(new KeyValuePair&lt;string, dynamic&gt;(f.Code, f.AttachedEntities[0].Get()));
                  }
                  else
                  {
                      expandoDic.Add(new KeyValuePair&lt;string, dynamic&gt;(f.Code, f.AttachedEntities.Select(e =&gt; e.Get())));
                  }
              }
              else
              {
                  expandoDic.Add(new KeyValuePair&lt;string, dynamic&gt;(f.Code, GetTypedValue(f.GetValueType(), val)));    
              }
  
          }
          else
          {
              expandoDic.Add(new KeyValuePair&lt;string, dynamic&gt;(f.Code, (dynamic)f.Values.Select(v =&gt; GetTypedValue(f.GetValueType(), v))));
          }
      }
      return expando;
  }
  </code></pre>
  
  <p>The <code>GetTypedValue</code> simply converts the string value into the appropriate type and returns <code>dynamic</code>.</p>
  
  <p>The problem I'm getting is that if I add a collection to <code>expandoDic</code> then I can't access the members without casting it to an <code>ICollection</code> type.  Consider the following code, where myPage is an ExpandoObject created by the above method.  </p>
  
  <pre><code>Response.Write(myPage.menu.items[0]);
  </code></pre>
  
  <p>The menu property is a dynamic object, as is <code>items</code>.  The latter is a collection of strings, though the type is actually <code>IEnumerable&lt;dynamic&gt;'.  If I inspect myPage.menu.items, it tells me the type is</code>dynamic {System.Linq.Enumerable.WhereSelectListIterator}`.  The above code produces the following error:</p>
  
  <pre><code>Cannot apply indexing with [] to an expression of type 'object'
  </code></pre>
  
  <p>If I use <code>First()</code> instead of an index, I instead get this error:</p>
  
  <pre><code>'object' does not contain a definition for 'First'
  </code></pre>
  
  <p>I understand that I could cast <code>items</code> to <code>IEnumerable</code> and fix the problem right away, but I am writing a development framework and want to remove any barriers to developers using it.</p>