Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Function V3 Could not load file or assembly 'Microsoft.Extensions.DependencyModel, Version=3.1.6.0

We are trying to use the DependencyContext.Default.RuntimeLibraries to get all our project assemblies and load the types we want into the ServiceCollection. This code runs fine on asp.net core web application but when starting one of our Azure Function projects locally we get the following error:

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

Our Function is configured as below:

<Project Sdk="Microsoft.NET.Sdk">   
<PropertyGroup>
        <TargetFramework>netcoreapp3.1</TargetFramework>
        <AzureFunctionsVersion>v3</AzureFunctionsVersion>
        <UserSecretsId>...</UserSecretsId>   </PropertyGroup>   
<ItemGroup>
        <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
        <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="2.5.1" />
        <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="4.3.0" />
        <PackageReference Include="Microsoft.Azure.WebJobs.Host.Storage" Version="4.0.1" />
        <PackageReference Include="Microsoft.Azure.WebJobs.Logging.ApplicationInsights" Version="3.0.27" />
        <PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="3.1.18" />
        <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.13" />
        <PackageReference Include="System.Text.Json" Version="4.7.2" />   
</ItemGroup>
<ItemGroup>
        <None Update="host.json">
          <CopyToOutputDirectory>Always</CopyToOutputDirectory>
        </None>
        <None Update="local.settings.json">
          <CopyToOutputDirectory>Always</CopyToOutputDirectory>
          <CopyToPublishDirectory>Never</CopyToPublishDirectory>
        </None>   
</ItemGroup>   
<ItemGroup>   
</ItemGroup> 
</Project>

The package is referenced through another project in the solution and we also tried referencing directly with no luck.

enter image description here

Does anyone know a workaround/fix to this problem?

like image 333
user351711 Avatar asked Aug 15 '26 15:08

user351711


1 Answers

Add the function preserved dependency in .csproj file of the function

<ItemGroup>
    <FunctionsPreservedDependencies Include="Microsoft.Extensions.DependencyModel.dll" />
</ItemGroup>
like image 52
Shani Bhati Avatar answered Aug 18 '26 05:08

Shani Bhati



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!