title: Visual Studio 2015 debugger showing null when object is not null
body: <p>If I run the following (admittedly contrived) program (VS2015, .NET4.6):</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          TestTaskAsync(null).Wait();
          TestTask(null);
      }
  
      public static async Task TestTaskAsync(
          EqualityComparer&lt;int&gt; comparer)
      {
          comparer = EqualityComparer&lt;int&gt;.Default;
  
          if (comparer == null)
          {
              Console.WriteLine("comparer is null");
          }
  
          Func&lt;int, bool&gt; func = i =&gt; comparer.Equals(i, 0);
      }
  
      public static Task TestTask(
          EqualityComparer&lt;int&gt; comparer)
      {
          comparer = EqualityComparer&lt;int&gt;.Default;
  
          if (comparer == null)
          {
              Console.WriteLine("comparer is null");
          }
  
          Func&lt;int, bool&gt; func = i =&gt; comparer.Equals(i, 0);
  
          return Task.CompletedTask;
      }
  }
  </code></pre>
  
  <p>then the program does exactly what I expect it to - i.e. it prints nothing to the console.</p>
  
  <p>However, when debugging, the debugger is telling me that <code>comparer</code> is null when it is not.</p>
  
  <p><a href="https://i.stack.imgur.com/yFx6y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yFx6y.png" alt="enter image description here"></a></p>
  
  <p>Note the following:</p>
  
  <ul>
  <li>The code does not enter the <code>if</code> block.</li>
  <li>The two debug values (both pinned and in the watch window) tell me<br>
  that <code>comparer</code> is null, even though it does not enter the if block.   </li>
  <li>The squiggly line and the greyed out code is telling me that<br>
  <code>comparer == null</code> can <em>never</em> be true. Which is correct, I think.</li>
  <li>This only happens in the method marked <code>async</code>.</li>
  </ul>
  
  <p>Finally, if I remove the line</p>
  
  <pre><code>Func&lt;int, bool&gt; func = i =&gt; comparer.Equals(i, 0);
  </code></pre>
  
  <p>Then the problem goes away.</p>
  
  <p>(Note. The point of the above program is to illustrate a problem I'm having in code that actually does something useful. This program is not actually expected to do anything.)</p>
  
  <p><strong>QUESTION</strong>:
  Does anyone know what is happening here?</p>