Azure / azure-functions-core-tools

Command line tools for Azure Functions
MIT License
1.32k stars 434 forks source link

Could not load file or assembly System.Net.Http.Formatting, Version=6.0.0.0 #3829

Open Eliran-Turgeman opened 1 month ago

Eliran-Turgeman commented 1 month ago

Version

4.0.6280 (latest, at the time of writing)

Description

I am using azure function app version 4, with .NET 8 in process mode, functions SDK version is 4.4.0.

One of the dependencies of my project is Microsoft.AspNet.WebApi.Client Version 6.0.0 (which includes the dll for System.Net.Http.Formatting (also in version 6.0.0)

When I try to run the function locally/deploy it, I get the same error -

Microsoft.Azure.WebJobs.Script: Error configuring services in an external startup class. System.Private.CoreLib: Unable to load one or more of the requested types. Could not load file or assembly 'System.Net.Http.Formatting, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified. Could not load file or assembly 'System.Net.Http.Formatting, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.

The dll of version 6.0.0 is in the function app - verified through Kudu, and by downloading the site content.

I think that our app first loads the azure-functions-core-tools dll with version 5.2.8, and by the time we try to load the correct dll with version 6.0.0 it fails because there was already an assembly with the same name loaded.

I think the fix here could be a new version of the tool with a bump to Microsoft.AspNet.WebApi.Client to version 6.0.0

Steps to reproduce

kratkaericd commented 1 week ago

Help!! I believe I am facing a similar issue with Microsoft.Extensions.Logging, also using azure function app version 4, with .NET 8 in process mode, Microsoft.NET.Sdk.Functions version is 4.4.1. I tried to upgrade Microsoft.NET.Sdk.Functions to 4.5.0 and got the same results. All of this worked fine yesterday before Azure Function Core Tools were upgraded from 4.83 to 4.95.

If there is a way to get Visual Studio to revert the Azure Function Core Tools it uses to an older version, please reply ASAP.

Error:

Azure Functions Core Tools
Core Tools Version:       4.0.6518 Commit hash: N/A +74ed9095fdd6c5326276aae6b8a7d41ccbdeb6aa (64-bit)
Function Runtime Version: 4.35.4.23179

[2024-10-17T22:25:58.322Z] Error configuring services in an external startup class. ....: Could not load file or assembly 'Microsoft.Extensions.Logging, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
...
C:\Users\...\AppData\Local\AzureFunctionsTools\Releases\4.95.0-inprocess\cli_x64\func.exe (process 22920) exited with code -1 (0xffffffff).

Project configuration:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFramework>net8.0</TargetFramework>
        <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    </PropertyGroup>
    <ItemGroup>
        <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.10" />
        <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
        <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.4.1" />
        <PackageReference Include="Microsoft.SemanticKernel" Version="1.21.1" />
        <PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
kratkaericd commented 1 week ago

Solution for me: Add "FUNCTIONS_INPROC_NET8_ENABLED": "1" in local.settings.json.