Search code examples
c#.netmigration.net-6.0

.NET 6 System.IO.FileNotFoundException: Could not load file or assembly System.Linq, Version=6.0.0.0


I am trying to migrate a project from .NET Core 3.1 to .NET 6. I have followed the official migration guide from Microsoft.

During build in startup.Configure I get

System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Linq, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.'

This is .csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
    <AssemblyName>Omicron.Insurance.Runner</AssemblyName>
    <RootNamespace>Omicron.Insurance.Runner</RootNamespace>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Omicron.Insurance.Entities" Version="1.0.139" />
    <PackageReference Include="Omicron.Platform.Web.ApplicationInsights" Version="3.1.60" />
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
    <PackageReference Include="Microsoft.Azure.ServiceBus" Version="5.2.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration.AzureKeyVault" Version="3.1.22" />
      <PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.1" />
      <PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="6.0.1" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.0.1" />
    <PackageReference Include="NodaTime" Version="3.0.9" />
    <PackageReference Include="ServiceBus.AttachmentPlugin" Version="6.2.0" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

Solution

  • I had to update AzureFunctionsVersion from v3 to v4. That solved the issue. Upgrading Azure Functions wasn't mentioned in the official migration guide from Microsoft.

    EDIT: you also need to upgrade the Azure Function App as well.

    https://learn.microsoft.com/en-us/azure/azure-functions/functions-versions?tabs=in-process%2Cv4&pivots=programming-language-csharp#migrating-from-3x-to-4x