title: this == null inside .NET instance method - why is that possible?
body: <p>I've always thought that it's impossible for <code>this</code> to be null inside instance method body. Following simple program demonstrates that it is possible. Is this some documented behaviour?</p>
  
  <pre><code>class Foo
  {
      public void Bar()
      {
          Debug.Assert(this == null);
      }
  }
  
  public static void Test()
  {            
      var action = (Action)Delegate.CreateDelegate(typeof (Action), null, typeof(Foo).GetMethod("Bar"));
      action();
  }
  </code></pre>
  
  <p>UPDATE</p>
  
  <p>I agree with the answers saying that it's how this method is documented. However, I don't really understand this behaviour. Especially because it's not how C# is designed.</p>
  
  <blockquote>
    <p>We had gotten a report from somebody (likely one of the .NET groups
    using C# (thought it wasn't yet named C# at that time)) who had
    written code that called a method on a null pointer, but they didn’t
    get an exception because the method didn’t access any fields (ie
    “this” was null, but nothing in the method used it). That method then
    called another method which did use the this point and threw an
    exception, and a bit of head-scratching ensued. After they figured it
    out, they sent us a note about it.
    We thought that being able to call a method on a null instance was a
    bit weird. Peter Golde did some testing to see what the perf impact
    was of always using callvirt, and it was small enough that we decided
    to make the change.</p>
  </blockquote>
  
  <p><a href="http://blogs.msdn.com/b/ericgu/archive/2008/07/02/why-does-c-always-use-callvirt.aspx" rel="noreferrer">http://blogs.msdn.com/b/ericgu/archive/2008/07/02/why-does-c-always-use-callvirt.aspx</a></p>