NuGet package issue (DLL cannot be found)

Brian Vind Borgstrøm 0 Reputation points
2025-02-05T10:36:38.13+00:00

Hello,

I have an Azure Functions project in Visual Studio 2022 (with the latest patch installed). I initially developed this project using .NET 6.0 about a year ago, and everything was working fine.

Recently, I updated the project to .NET 8.0 and upgraded all the old NuGet packages. The update completed successfully, and the project builds without issues.

However, when running the project locally in debug mode (x64), I encounter the following 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

[2025-02-05T10:21:58.365Z] Found C:\Users\bvb\source\repos\Connect4Azure\Connect4Azure.csproj. Using for user secrets file configuration.

[2025-02-05T10:22:00.381Z] Error configuring services in an external startup class.

[2025-02-05T10:22:00.408Z] Error configuring services in an external startup class.

Connect4Azure: Could not load file or assembly 'Microsoft.Extensions.Configuration.Abstractions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.


I also tried using Microsoft.Extensions.Configuration.Abstractions version 9.0.1, but the error persists. The Microsoft.Extensions.Configuration.Abstractions.dll file is located in the correct directory on the file system, and its version appears to be correct.

Can anyone provide insight into why this error is occurring?

Best regards,

Brian

Developer technologies | ASP.NET | ASP.NET Core
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. MohaNed Ghawar 155 Reputation points
    2025-02-05T11:37:55.5766667+00:00

    1-Clean up the NuGet cache and packages:

    dotnet nuget locals all --clear

    2-Delete the following directories in your project:

    • bin
    • obj
    • .vs

    3-Restore your NuGet packages:

    dotnet restore

    4-Rebuild your project:

    dotnet restore

    1. Make sure your Microsoft.NET.Sdk.Functions package version is compatible with .NET 8.0. You should be using version 4.2.0 or later.
    2. Verify these key package versions in your .csproj file: <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.2.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
    0 comments No comments

  2. Raymond Huynh (WICLOUD CORPORATION) 620 Reputation points Microsoft External Staff
    2025-07-08T08:12:43.55+00:00

    If you’re still facing the error about Microsoft.Extensions.Configuration.Abstractions not being found after upgrading to .NET 8, try these additional steps:

    1. Check for Transitive Dependency Conflicts:

    • Sometimes, other NuGet packages reference different versions of Microsoft.Extensions.Configuration.Abstractions. Use the following command to inspect your dependency tree:
    dotnet list package --include-transitive
    
    • Look for any mismatched versions and align them in your .csproj by adding explicit PackageReference entries if needed.

    2. Ensure All Projects Target the Same .NET Version:

    • If your solution has multiple projects, make sure they all target .NET 8.0 and use compatible package versions. Mixing frameworks can cause assembly loading issues.

    3. Remove and Re-add the Problematic Package:

    • Sometimes, simply removing and re-adding the package can resolve hidden issues:
    dotnet remove package Microsoft.Extensions.Configuration.Abstractions
    dotnet add package Microsoft.Extensions.Configuration.Abstractions --version 8.0.0
    

    4. Check Your Local Function Tools Version:

    • Make sure your Azure Functions Core Tools are up to date and compatible with .NET 8. You can update them with:
     npm i -g azure-functions-core-tools@4 --unsafe-perm true
    

    5. Check for Binding Redirects (if using .config files):

    • In some cases, especially with older projects, you may need to add or update binding redirects in your app.config or web.config to point to the correct assembly version.

    6. Try a Clean Clone:

    • If all else fails, clone your repository into a new directory, restore packages, and build. This can rule out any local environment issues.

    .NET projects can sometimes get “confused” if there are version mismatches, stale caches, or transitive dependencies pulling in the wrong DLL versions. The above steps help ensure your project and all its dependencies are aligned and clean.

    If you try these steps and still have issues, please share your .csproj file and the full error message for more targeted help!


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.