title: Why does the C# compiler not fault code where a static method calls an instance method?
body: <p>The following code has a static method, <code>Foo()</code>, calling an instance method, <code>Bar()</code>:</p>
  
  <pre><code>public sealed class Example
  {
      int count;
  
      public static void Foo( dynamic x )
      {
          Bar(x);
      }
  
      void Bar( dynamic x )
      {
          count++;
      }
  }
  </code></pre>
  
  <p>It compiles without error* but generates a runtime binder exception at runtime. Removing the dynamic parameter to these methods causes a compiler error, as expected.</p>
  
  <p>So why does having a dynamic parameter allow the code to be compiled? ReSharper doesn't show it as an error either.</p>
  
  <p><strong>Edit 1:</strong> *in Visual Studio 2008</p>
  
  <p><strong>Edit 2:</strong> added <code>sealed</code> since it's possible that a subclass could contain a static <code>Bar(...)</code> method. Even the sealed version compiles when it's not possible that any method other than the instance method could be called at runtime.</p>