7

I've been getting this error message when I try to run my Azure function v4.

System.IO.FileNotFoundException: 'Could not load file or assembly 'Microsoft.Extensions.Options, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.'

This used to work like a week ago, and now it's throwing this error at runtime. Latest changes I did was to update EF Core to version 7. But I guess that's not relevant because that's in a different project, so not related to the function project.

These are the package references in my function project:

<PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
    <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
    <PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.3" />
  </ItemGroup>

Has anyone else got it or any idea how to resolve it?

Tried removing all the Nuget packages and installing them. That didn't work. I can see the Microsoft.Extensions.Options.dll (v7) in the debug folder as well. Not sure why the runtime complains about it.

I recently updated to VS 2022 Version 17.4.1. Maybe that's the issue here?

Thusitha
  • 165
  • 1
  • 12
  • Post the `` elements from your `.csproj` - don't post a screenshot of the NuGet UI - which also doesn't show that you have `Microsoft.Extensions.Options` added anyway... – Dai Nov 17 '22 at 05:31
  • @Dai added the package references as well. – Thusitha Nov 17 '22 at 05:43
  • [don't post pictures of code...](https://meta.stackoverflow.com/questions/285551/why-should-i-not-upload-images-of-code-data-errors) – Dai Nov 17 '22 at 05:43
  • I hope everything is in order now.. – Thusitha Nov 17 '22 at 06:00
  • The same packages you have given is working fine in .NET 6 AF project https://i.imgur.com/lWiCJA2.png. And it is working fine in .NET 7 isolated when I remove Microsoft.NET.Sdk.Functions (last package). https://i.imgur.com/WnU8irc.png . – RithwikBojja Nov 17 '22 at 06:45
  • .Net 7 is not available yet. So, please update to .NET 7 isolated and it works fine. – RithwikBojja Nov 17 '22 at 06:46
  • Thanks @RithwikBojja. I actually started with .NET 6 and switched to .NET 7. Now I've switched back to .NET 6. But still not seems to be working :( – Thusitha Nov 17 '22 at 08:53
  • In .Net 6 try to rebuild and reinstall all nuget packages as it is working fine in .Net 6 – RithwikBojja Nov 17 '22 at 08:54
  • I seems to be getting into the same situation no matter what I try :( – Thusitha Nov 17 '22 at 09:13
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/249692/discussion-between-thusitha-and-rithwikbojja). – Thusitha Nov 17 '22 at 09:14

2 Answers2

7

I have reproduced in my environment,I have observed that the same packages you have given is working fine in .NET 6 Azure functions project

And it is working fine in .NET 7 isolated when I remove Microsoft.NET.Sdk.Functions (last package).

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

As discussed in comments Try to degrade

Microsoft.Extensions.Configuration.Abstractions nuget package to Version="6.0.0". Try to revert back to older versions

H. Pauwelyn
  • 13,575
  • 26
  • 81
  • 144
RithwikBojja
  • 5,069
  • 2
  • 3
  • 7
  • In addition to this, I've reverted most of the version 7+ packages which I upgraded. That was including EF Core 7.0.0.. – Thusitha Nov 17 '22 at 11:12
  • 3
    But I am targeting to upgrade EF 7.0.0. What shall I do ? Facing the same error – ispostback Dec 15 '22 at 11:48
  • 1
    I found per [this thread on github](https://github.com/Azure/azure-functions-core-tools/issues/2304) that it sometimes takes a few weeks for MS to iron out issues with the packages between EF, Functions and probably some other cases. This however has been a few months already... `Logging.Abstratctions` works, `DependencyInjection` works on v7 packages. Is this still the issue with Functions and the `Configuration.Abstractions` package or is it some other issue? Is there an issue to track for an ETA on fixes? – interesting-name-here Mar 20 '23 at 15:58
2

I had the same problem with identical symptoms. It turns out that the cause, in my case, was the latest Microsoft.Extensions.Options.DataAnnotations package. I was using v7.0.0 and downgrading to the previous version v6.0.0 solved the problem.

Here is my project file for what it's worth:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <Nullable>enable</Nullable>
    <EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
    <AnalysisLevel>preview-recommended</AnalysisLevel>
  </PropertyGroup>
  <ItemGroup>
    <None Remove=".gitignore" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="2.9.1" />
    <PackageReference Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" Version="5.2.0" />
    <PackageReference Include="Microsoft.Extensions.Options.DataAnnotations" Version="6.0.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.3" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

Thanks @RithwikBojja for your help and pointer...

Kaine
  • 521
  • 1
  • 4
  • 12