5

I am deploying an Azure Function called "Bridge" to Azure, targeting .NET 6. The project is referencing a class library called "DBLibrary" that I wrote, and that library is targeting .NET Standard 2.1. The Azure Function can be run locally on my PC without runtime errors.

When I publish the Azure Function to Azure, I see in Azure Portal a "Functions runtime error" which says:

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

I do not target System.ComponentModel directly, and I don't see a nuget package version 6.0.0 for "System.ComponentModel" available from any nuget feed. Why is the Azure function looking for this version 6.0.0 of System.ComponentModel? If that version does exist, why can't the Azure Function find it?

Here are the relevant parts of the csproj for the "Bridge" Azure Function:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
      <TargetFramework>net6.0</TargetFramework>
      <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    </PropertyGroup>
    <ItemGroup>
      <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
      <PackageReference Include="Microsoft.Extensions.Azure" Version="1.1.1" />
      <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
      <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.0.1" />
    </ItemGroup>
    <ItemGroup>
      <ProjectReference Include="..\DBLibrary\DBLibrary.csproj" />
    </ItemGroup>
</Project>

Here are the relevant sections of the csproj for the "DBLibrary" class library that is referenced by the Azure Function project:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
      <TargetFramework>netstandard2.1</TargetFramework>
      <ApplicationIcon />
      <OutputType>Library</OutputType>
      <StartupObject />
    </PropertyGroup>
    <ItemGroup>
      <PackageReference Include="Azure.Storage.Blobs" Version="12.10.0" />
      <PackageReference Include="Dapper" Version="2.0.123" />
      <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
      <PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
      <PackageReference Include="System.Text.Json" Version="6.0.2" />
    </ItemGroup>
</Project>

I have tried setting _FunctionsSkipCleanOutput to true in the Azure Functions csproj because that was offered as a potential solution to nuget package resolution issues here: https://github.com/Azure/azure-functions-host/issues/7061 That solution did not change the runtime error I saw in the Azure portal.

Scott Carpenter
  • 131
  • 1
  • 9

3 Answers3

12

If you have upgraded to .NET 6.0 you need to do the following to get past this error.

  1. Update the cs proj to v4 enter image description here

  2. Update the configuration in your function app in Azure to below enter image description here

  3. Update all the nuget packages for the solution

Clean the solution and then rebuild and it should work locally and should also work in Azure

Ricky Gummadi
  • 4,559
  • 2
  • 41
  • 67
8

In my deployment pipeline, I was targeting functions runtime version ~2 for the Azure deployment when I should have been targeting version ~4 to support .NET 6. Changing to target version 4 of the Azure Functions runtime fixed the issue.

To find this setting on a deployed Function App, navigate to the Azure Portal (portal.azure.com) and search for the Function App resource's name there. Under the left navigation bar of the Function App, navigate to Settings > Configuration. After selecting the Configuration section, look for "Function runtime settings" at the top of the right pane to verify the Runtime version is "~4".

The function runtime version differences can be found here: https://learn.microsoft.com/en-us/azure/azure-functions/functions-versions?tabs=in-process%2Cv4&pivots=programming-language-csharp

This is the relevant part of the support table from the link above (as of February 2022):

Version Support Level Description
4.x GA Recommended runtime version for functions in all languages. Use this version to run C# functions on .NET 6.0.
Scott Carpenter
  • 131
  • 1
  • 9
0

The .net standard you are using 2.1 but ,Microsoft.Azure.Functions.Extensions can be support upto .NET Standard 2.0

You should add the below package to your function app and deploy to Azure again.

 dotnet add package Microsoft.EntityFrameworkCore.SqlServer --version 5.0.0-rc.2.20475.6

Please refer this GitHub issue and this MICROSOFT BLOG by @Jeremy for more information.

AjayKumarGhose
  • 4,257
  • 2
  • 4
  • 15
  • I tried downgrading my class library to .NET Standard 2.0 from 2.1, but that did not fix my issue while deployed in Azure. Your suggestion about EntityFramework is not relevant because I am not using Entity Framework in either of the two projects. – Scott Carpenter Feb 28 '22 at 14:37