title: Why does AsyncLocal<T> return different results when code is refactored slightly?
body: <p>When I call <code>WrapperAsync</code> <code>AsyncLocalContext.Value</code> returns null. When I run the same code block outside the method, in the <code>Main</code> method, <code>AsyncLocalContext.Value</code> is not null (which is what I would expect).</p>
  
  <p>The functionality is exactly the same yet the results are different. Is this a bug with the <code>Asynclocal</code> class or is there another explanation?</p>
  
  <pre><code>internal class Program
  {
      private static readonly AsyncLocal&lt;string&gt; AsyncLocalContext = new AsyncLocal&lt;string&gt;();
  
      private static void Main()
      {
          const string text = "surprise!";
  
          WrapperAsync(text).Wait();
          Console.WriteLine("Get is null: " + (AsyncLocalContext.Value == null));
          // AsyncLocalContext.Value is null
  
          var value = GetValueAsync(text).Result;
          AsyncLocalContext.Value = value;
          Console.WriteLine("Get is null: " + (AsyncLocalContext.Value == null));
          // AsyncLocalContext.Value is not null
          Console.Read();
      }
  
      private static async Task WrapperAsync(string text)
      {
          var value = await GetValueAsync(text);
          AsyncLocalContext.Value = value;
      }
  
      private static async Task&lt;string&gt; GetValueAsync(string text)
      {
          await Task.Delay(0);
          return text;
      }
  }
  </code></pre>