title: Why can't I subscribe to HttpHandlerDiagnosticListener in a .NET Framework application
body: <p>I am using the code below to enable <code>System.Net.Http.HttpClient</code>s to create an activity for every outgoing HTTP request. This works well in an ASP.NET Core application that targets .NET Core 3.1 but it does not work in a 'classic' ASP.NET application that targets .NET Framework 4.7.2.</p>
  <pre class="lang-cs prettyprint-override"><code>// Using the Subscribe(IObservable&lt;T&gt;, Action&lt;T&gt;) extension method from the System.Reactive package
  DiagnosticListener.AllListeners.Subscribe(listener =&gt;
  {
      if (listener.Name == &quot;HttpHandlerDiagnosticListener&quot;)
      {
          listener.Subscribe(diagnostic =&gt;
          {
              if (diagnostic.Key == &quot;System.Net.Http.HttpRequestOut.Start&quot;)
              {
                  // ...
              }
              else if (diagnostic.Key == &quot;System.Net.Http.HttpRequestOut.Stop&quot;)
              {
                  // ...
              }
          }
      }
  }
  </code></pre>
  <p>The main difference that I can think of is that the ASP.NET Core application uses the <code>DiagnosticListener</code> type that is built-in to .NET Core, whereas the 'classic' ASP.NET application needs a package reference to System.Diagnostics.DiagnosticSource to use that type.</p>
  <p>I tried with different versions of the System.Diagnostics.DiagnosticSource package (4.6.0, 4.7.0, 4.7.1, 5.0.0, and 5.0.1), rebuilding my project after each up/downgrade of the package, but to no avail.</p>
  <p>I found a <a href="https://github.com/Azure/azure-functions-host/issues/7135" rel="nofollow noreferrer">GitHub issue about a similar problem in Azure Functions (in-process) applications</a>. They mention downgrading to System.Diagnostics.DiagnosticSource 4.7.0 as a workaround, but in my tests that does not work.</p>