title: HAA0502 Explicit new reference type allocation
body: <p>I have <code>ASP.Net Core 2.1</code>, <code>C#</code> application. I am using <strong>Clr Heap Allocation Analyzer</strong></p>
  
  <p><a href="https://marketplace.visualstudio.com/items?itemName=MukulSabharwal.ClrHeapAllocationAnalyzer" rel="noreferrer">https://marketplace.visualstudio.com/items?itemName=MukulSabharwal.ClrHeapAllocationAnalyzer</a></p>
  
  <p>One of the methods looks as below</p>
  
  <p>Ex#1</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services) {
  
  services.AddSingleton&lt;IPocoDynamo&gt;(serviceProvider =&gt; {
      var pocoDynamo = new PocoDynamo(serviceProvider.GetRequieredService&lt;IAmazonDynamoDB&gt;());
      pocoDynamo.SomeMethod();
      return pocoDynamo;
  });
  </code></pre>
  
  <p>}</p>
  
  <p>Ex.#2</p>
  
  <pre><code>public async Task&lt;EventTO&gt; AddEvent(EventTO eventObj)
  {
    try
      {       
        throw new Exception("Error!");
      }
   catch (Exception ex)
   {
     Logger.Log(ex, eventObj);
     return null;
    }
  }
  </code></pre>
  
  <p>I am using DI throughout the app. But wherever the analyzer is finding <code>new</code> keyword thing, it is warning as</p>
  
  <blockquote>
    <p>HAA0502   Explicit new reference type allocation </p>
  </blockquote>
  
  <p>Also wherever Lambda expression is used, it is warning as (like in ex#1)</p>
  
  <pre><code>Warning HAA0301 Heap allocation of closure Captures:
  </code></pre>
  
  <p>What is causing this &amp; how to address this?</p>
  
  <p>Thanks!</p>