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
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.
Same Redis connection code works normally as expected outside the Azure function.
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
function uses Startup
[assembly: FunctionsStartup(typeof(...))]
The project file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.0.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventHubs" Version="4.1.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.3" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" />
<PackageReference Include="System.Memory" Version="4.5.3" />
<PackageReference Include="Utf8Json" Version="1.3.7" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="....ConfigurationConfiguration.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
What’s wrong?
3
Answers
The problem was fixed by changing the Azure functions version to v3 in project .csproj file.
Can you try to add true to your .csproj file:
If the problem persists, verify that you are using the correct version of Azure Functions Core Tools (v3), it happened to me that I took version 2 from nodejs that is, I had version 2 installed in nodejs and version 3 in the folder From microsoft in the path they were both but I took the first one that was the nodejs one and it kept giving me the error until I delete the nodejs one, you can update it to version 3 in nodejs and I suppose it will work the same.