title: Why doesn't the null coalescing operator (??) work in this situation?
body: <p>I'm getting an unexpected <code>NullReferenceException</code> when I run this code, omitting the <code>fileSystemHelper</code> parameter (and therefore defaulting it to null):</p>
  
  <pre><code>public class GitLog
      {
      FileSystemHelper fileSystem;
  
      /// &lt;summary&gt;
      ///   Initializes a new instance of the &lt;see cref="GitLog" /&gt; class.
      /// &lt;/summary&gt;
      /// &lt;param name="pathToWorkingCopy"&gt;The path to a Git working copy.&lt;/param&gt;
      /// &lt;param name="fileSystemHelper"&gt;A helper class that provides file system services (optional).&lt;/param&gt;
      /// &lt;exception cref="ArgumentException"&gt;Thrown if the path is invalid.&lt;/exception&gt;
      /// &lt;exception cref="InvalidOperationException"&gt;Thrown if there is no Git repository at the specified path.&lt;/exception&gt;
      public GitLog(string pathToWorkingCopy, FileSystemHelper fileSystemHelper = null)
          {
          this.fileSystem = fileSystemHelper ?? new FileSystemHelper();
          string fullPath = fileSystem.GetFullPath(pathToWorkingCopy); // ArgumentException if path invalid.
          if (!fileSystem.DirectoryExists(fullPath))
              throw new ArgumentException("The specified working copy directory does not exist.");
          GitWorkingCopyPath = pathToWorkingCopy;
          string git = fileSystem.PathCombine(fullPath, ".git");
          if (!fileSystem.DirectoryExists(git))
              {
              throw new InvalidOperationException(
                  "There does not appear to be a Git repository at the specified location.");
              }
          }
  </code></pre>
  
  <p>When I single step the code in the debugger, after I step over the first line (with the <code>??</code> operator) then <code>fileSystem</code> still has the value null, as shown in this screen snip (stepping over the next line throws <code>NullReferenceException</code>):
  <img src="https://i.stack.imgur.com/HkDtr.png" alt="When is null not null?"></p>
  
  <p>This is not what I expected! I'm expecting the null coalescing operator to spot that the parameter is null and create a <code>new FileSystemHelper()</code>. I have stared at this code for ages and can't see what is wrong with it.</p>
  
  <p>ReSharper pointed out that the field is only used in this one method, so could potentially be converted to a local variable... so I tried that and guess what? It worked. So, I have my fix, but I cannot for the life of me see why the code above doesn't work. I feel like I am on the edge of learning something interesting about C#, either that or I've done something really dumb. Can anyone see what's happening here?</p>