title: C# interface method declaration - cannot execution implemention
body: <p>I have a concrete class implementation of an interface that has a method declaration like so....</p>
  
  <pre><code>public interface IControllerContent
  {
       IEnumerable&lt;KeyValuePair&lt;string, string&gt;&gt; LocalResource();
  }
  
  public class BaseControllerContent : IControllerContent
  {
  
     public IEnumerable&lt;KeyValuePair&lt;string, string&gt;&gt; LocalResource()
     {
       ResourceSet resourceSet =
       ResourceManager.GetResourceSet(new CultureInfo(this.Tenant.Locale), true, false);
  
       IDictionaryEnumerator dictionaryEnumerator = resourceSet.GetEnumerator();
  
          while (dictionaryEnumerator.MoveNext())
          {
              //only string resources
              var value = dictionaryEnumerator.Value as string;
              if (value != null)
              {
                  var key = (string)dictionaryEnumerator.Key;
                  yield return new KeyValuePair&lt;string, string&gt;(key, value);
              }
          }
      }
  }
  </code></pre>
  
  <p>All fairly straight forward. Declare an interface and implement from a concrete class.
  However when I try to call the LocalResource method of the concrete class I get an exception.</p>
  
  <pre><code>public T Build&lt;T&gt;() where T : class, IControllerContent
  {
       var controllerContent = Activator.CreateInstance(typeof(T)) as T;
       try
       {
           **controllerContent.CDict = (Dictionary&lt;string, string&gt;) controllerContent.LocalResource();**
           controllerContent.CDict = (Dictionary&lt;string, string&gt;) JsonReader&lt;T&gt;.Parse(this.Content);
           return controllerContent;
        }
        catch (Exception ex)
        {
           throw new Exception();
        }
  }
  </code></pre>
  
  <p>The exception occurs when trying to execute the LocalResource() method (highlighted above).</p>
  
  <p>{System.InvalidCastException: Unable to cast object of type '&lt;LocalResource&gt;d__0' to type 'System.Collections.Generic.Dictionary`2[System.String,System.String]'.
     at FantasyLeague.Web.Mvc.ControllerContentBuilder.BuildT in C:\Users\andrew.knightley\git\FAST\src\ContentManagement\FantasyLeague.Web.Mvc\ControllerBase.cs:line 290}</p>
  
  <p>Basically it appears that C# is trying to parse the interface method signature as a Dictionary, hence the error, however surely it should be trying to execute the concrete implementation.
  Anyone know whats going on here?
  I've tried casting to interface and concrete type and all combinations, it still isn't having it.
  I have reread all the MSDN stuff on interfaces, according to their articles there is nothing out of the ordinary here.</p>
  
  <p>Many thanks in advance.</p>