title: Azure function v2, Core 3.1 Could not load file or assembly System.Memory, Version=4.2.0.0
body: <p>I'm running locally an Azure function v2 on Core 3.1. Function connects reads events from an EventHub and write data to a Redis database.
  While connecting function gets an error</p>
  
  <pre><code>System.Private.CoreLib: Exception while executing function: 
   One or more errors occurred. (Could not load file or assembly 'System.Memory, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.). 
   Pipelines.Sockets.Unofficial: Could not load file or assembly 'System.Memory, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified. System.Private.CoreLib: Could not load the specified file.
  </code></pre>
  
  <p>Same Redis connection code works normally as expected outside the Azure function.</p>
  
  <p>I have installed System.Memory nuget package v 4.5.3 into the project but it does not help.
  There is no System.Memory version 4.2 listed in nuget for Core 3.1</p>
  
  <p>function uses Startup</p>
  
  <pre><code>[assembly: FunctionsStartup(typeof(...))]
  </code></pre>
  
  <p>The project file</p>
  
  <pre><code>&lt;Project Sdk="Microsoft.NET.Sdk"&gt;
    &lt;PropertyGroup&gt;
      &lt;TargetFramework&gt;netcoreapp3.1&lt;/TargetFramework&gt;
      &lt;AzureFunctionsVersion&gt;v2&lt;/AzureFunctionsVersion&gt;
    &lt;/PropertyGroup&gt;
    &lt;ItemGroup&gt;
      &lt;PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.0.0" /&gt;
      &lt;PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventHubs" Version="4.1.0" /&gt;
      &lt;PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.3" /&gt;
      &lt;PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" /&gt;
      &lt;PackageReference Include="System.Memory" Version="4.5.3" /&gt;
      &lt;PackageReference Include="Utf8Json" Version="1.3.7" /&gt;
    &lt;/ItemGroup&gt;
    &lt;ItemGroup&gt;
      &lt;ProjectReference Include="..\..\Configuration\Configuration.csproj" /&gt;
    &lt;/ItemGroup&gt;
    &lt;ItemGroup&gt;
      &lt;None Update="host.json"&gt;
        &lt;CopyToOutputDirectory&gt;PreserveNewest&lt;/CopyToOutputDirectory&gt;
      &lt;/None&gt;
      &lt;None Update="local.settings.json"&gt;
        &lt;CopyToOutputDirectory&gt;PreserveNewest&lt;/CopyToOutputDirectory&gt;
        &lt;CopyToPublishDirectory&gt;Never&lt;/CopyToPublishDirectory&gt;
      &lt;/None&gt;
    &lt;/ItemGroup&gt;
  &lt;/Project&gt;
  </code></pre>
  
  <p>What's wrong?</p>