skip to Main Content

I have a Visual Studio project (.NET Core 8, Azure Functions v4) which "works on any machine except mine".

The error message is:

The ‘—‘ function is in error: Could not load file or assembly ‘X.X.X, Version=8.0.0.0, Culture=neutral, PublicKeyToken=…’. The system cannot find the file specified.

And it really makes no difference which package I import System.Net.Http, System.Security.Cryptography.X509Certificates – it can’t find anything at all.

Depending on which code I comment out and remove imports the message is slightly different:

Error configuring services in an external startup class.

XXX.Consumer: Could not load file or assembly ‘System.Net.Http, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’. The system cannot find the file specified.

A host error has occurred during startup operation ‘106f06bc-2885-4839-abfe-c23ed98b7b26’.

Microsoft.Azure.WebJobs.Script: Error configuring services in an external startup class. XXX.Consumer: Could not load file or assembly ‘System.Net.Http, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’. The system cannot find the file specified.

Other Azure Function projects work fine, but this one is "stuck".

Same issue in Visual Studio 2022 – Community or Professional.

I have read dozens of similar questions here and tried:

  • Clean and rebuild solution/project
  • Restart vs
  • Running Release vs Debug
  • Deleting entire Debug/Release Directories
  • Updating al NuGet packages
  • Opening my bin/Debug/net8.0/Project.dll in DependencyWalker (see below)

DependencyWalker is showing a gazillion "Error opening file." messages as well as:

Error: At least one required implicit or forwarded dependency was not found.
Error: Modules with different CPU types were found.
Warning: At least one delay-load dependency module was not found.
Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.

enter image description here

UPDATE:

C# Project file

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="AutoMapper" Version="13.0.1" />
    <PackageReference Include="Azure.Data.SchemaRegistry" Version="1.4.0" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventHubs" Version="6.3.5" />
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />

    <PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
    <PackageReference Include="Microsoft.Extensions.Options.DataAnnotations" Version="8.0.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.4.1" />
    <PackageReference Include="Newtonsoft.Json.Schema" Version="4.0.1" />

  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

dotnet –list-sdks

8.0.204 [C:Program Filesdotnetsdk]

FYI: I installed .NET v6 later to see if it helped (since CoreToolsHost was logging "Loading .NET 6 host") but this did not help.

2

Answers


  1. Chosen as BEST ANSWER

    Solved by adding the following line to local.settings.json:

    "FUNCTIONS_INPROC_NET8_ENABLED": "1",
    

  2. We encountered the same issue while debugging an Azure Functions project locally. It had been working fine, but suddenly we started receiving the following error messages:

    Error configuring services in an external startup class.
    ... Could not load file or assembly 'Microsoft.Extensions.Logging.Abstractions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=*****'. The system cannot find the file specified.A host error has occurred during startup operation '****'.
    Microsoft.Azure.WebJobs.Script: Error configuring services in an external startup class. KnifConnect.Functions: Could not load file or assembly 
    ....
    

    Just wanted to add these error messages in case anyone else tries to search for a solution to this problem.

    The solution was as Marc mentioned:

    Add the following line to local.settings.json:

    "FUNCTIONS_INPROC_NET8_ENABLED": "1",
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search