When upgrading my Azure Functions app to .NET 7, I get the following error at runtime during startup:
System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Linq, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.'
I use the FunctionsStartup with the IFunctionsHostBuilder interface and since I use Binding types, I also use the AddWebJobs extension to be able to register an extension provider, like this:
var webJobsBuilder = builder.Services.AddWebJobs(x => { return; });
webJobsBuilder.AddExtension<AccessTokenExtensionProvider>();
That's where execution seems to fail. Is there any way to get this to work? Perhaps without having to use WebJobs? My code runs fine on .NET 6.
Initialy, instead of using the FunctionsStartup, I was using the WebJobsStartup, but that gave the same error. Not sure if System.Linq 7.0.0.0 even exists.
My project file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<UserSecretsId>34849d02-37f1-4724-b383-4d0896da65e4</UserSecretsId>
<_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Data.Tables" Version="12.6.1" />
<PackageReference Include="Azure.Storage.Files.Shares" Version="12.12.1" />
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Core" Version="1.8.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.CosmosDB" Version="3.0.10" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventHubs" Version="5.1.2" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="5.8.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="5.0.1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Host.Storage" Version="4.1.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" Version="5.1.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
<PackageReference Include="Microsoft.IdentityModel.Protocols" Version="6.25.0" />
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="6.25.0" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.25.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.3" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.25.0" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\PublishProfiles\" />
</ItemGroup>
</Project>
Startup file:
using System.Linq;
using SampleProject.Portal.Api;
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using SampleProject.Portal.Api.B2C;
[assembly: FunctionsStartup(typeof(Startup))]
namespace SampleProject.Portal.Api;
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
ServiceDescriptor logger = builder.Services.FirstOrDefault(s => s.ServiceType == typeof(ILogger<>));
if (logger != null)
{
builder.Services.Remove(logger);
}
builder.AddAccessTokenBinding();
}
}
I have the same issue and I think I found the solution, working on implementing it myself now. Functions have breaking changes in .net7 - they can only be run under the dotnet-isolated host model. The dotnet-isolated model requires slightly different setup code. It looks like Startup.cs might be deprecated in favor of Program.cs
https://learn.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-process-guide
This is a guide to the differences when using dotnet-isolated. If you make a new function project using the new .net7 (isolated) template you'll see the differences