0

while running my azure functions, I am getting this exception in startup class. Even after installing this package error persist. System.IO.FileNotFoundException: 'Could not load file or assembly 'Microsoft.Extensions.Configuration.Abstractions, Version=9.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.' this is my startup class. Project is using .net8 with v4

#region Dependency
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
#endregion

[assembly: FunctionsStartup(typeof(HROne.Events.FunctionApp.Startup))]
namespace HROne.Events.FunctionApp;

public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
    FunctionsHostBuilderContext context = builder.GetContext();
    builder.Services.RegisterApplicationServices(context.ApplicationRootPath);
}
}

Below is the .csproj file code

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<None Remove="AzureAppConfigurationMapper.json" />
<None Remove="EmailTemplate\CommonNotificationMail.html" />
<None Remove="EmailTemplate\DeadLetterInfo.html" />
<None Remove="EmailTemplate\TimesheetReminderMail.html" />
</ItemGroup>
<ItemGroup>

<Content Include="EmailTemplate\CommonNotificationMail.html">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="EmailTemplate\DeadLetterInfo.html">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Content Include="AzureAppConfigurationMapper.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="EmailTemplate\TimesheetReminderMail.html">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Azure.Messaging.EventHubs" Version="5.11.5" />
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="2.13.5" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="5.16.4" />
<PackageReference Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" Version="7.3.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.4.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\HROne.BusinessLayer\HROne.Events.Services\HROne.Events.Services.csproj" />
<ProjectReference Include="..\..\HROne.BusinessLayer\HROne.Redis\HROne.Redis.csproj" />
<ProjectReference Include="..\..\HROne.BusinessLayer\HROne.Shared.Services\HROne.Shared.Services.csproj" />
<ProjectReference Include="..\..\HROne.DataModels\HROne.Events.Models\HROne.Events.Models.csproj" />
<ProjectReference Include="..\..\HROne.Repositories\HROne.Events.Repositories\HROne.Events.Repositories.csproj" />
<ProjectReference Include="..\..\HROne.Shared\HROne.Common\HROne.Common.csproj" />
</ItemGroup>
<ItemGroup>
<Using Include="HROne.Constants" />
</ItemGroup>
<ItemGroup>
<None Update="AppSettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="AppSettings.Test.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="EmailTemplate\ImportException.html">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="EmailTemplate\ImportPartial.html">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="EmailTemplate\MailTemplateImages\hrone_btn.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="EmailTemplate\MailTemplateImages\Welcome_header.jpg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="EmailTemplate\NotificationMail.html">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="EmailTemplate\SingleSignOnWelcome.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="EmailTemplate\Welcome.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="EmailTemplate\WelcomeValidationMail.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="host.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="xcopy &quot;$(TargetDir)newrelic\*.*&quot; &quot;$(TargetDir)..\newrelic&quot; /Y /I /S" />
</Target>
</Project>
7
  • Downgrade to .NET 7 and use Microsoft.Extensions.* v7.0.0 for compatibility with Azure Functions v4. Commented Apr 9 at 7:21
  • Provide your .csproj code @pratapsingh845. Commented Apr 9 at 7:24
  • 1
    Hi @PravallikaKV, file added please check now Commented Apr 9 at 8:34
  • 1
    @PravallikaKV yes, already did that but not working Commented Apr 9 at 8:41
  • 1
    @PravallikaKV, thanks for the quick support. I fixed this issue. There was one 'Serilog.AspNetCore' package that was creating this issue. I downgraded the version of this package, and it worked. Bcoz this package has dependency over 'Microsoft.Extensions.Configuration.Abstractions' this package. Commented Apr 14 at 5:26

1 Answer 1

1

Upgrade Microsoft.Extensions.Configuration.AzureAppConfiguration and Microsoft.Extensions.Configuration.AzureAppConfiguration packages to the corresponding latest versions.

Add "FUNCTIONS_INPROC_NET8_ENABLED": "1" setting in local.settings.json.

local.settings.json:

{
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true",
        "FUNCTIONS_INPROC_NET8_ENABLED": "1",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet"
    }
}

I have created a .NET 8.0 in-process Durable Azure function and implemented Dependency Injection.

Startup.cs:

using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;

[assembly: FunctionsStartup(typeof(FunctionApp24.Startup))]
namespace FunctionApp24
{
    public class Startup : FunctionsStartup

    {
        public override void Configure(IFunctionsHostBuilder builder)
        {
            builder.Services.AddSingleton<IMyService, MyService>();
            FunctionsHostBuilderContext context = builder.GetContext();
            builder.Services.RegisterApplicationServices(context.ApplicationRootPath);
        }
    }
    public static class ServiceCollectionExtensions
    {
        public static void RegisterApplicationServices(this IServiceCollection services, string applicationRootPath)
        {
            services.AddSingleton<IMyService, MyService>();
        }
    }
}

.csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
  <PackageReference Include="Azure.Messaging.EventHubs" Version="5.11.5" />
  <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
  <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="2.13.5" />
  <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="5.16.4" />
  <PackageReference Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" Version="7.3.0" />
  <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.4.1" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

IMyService.cs:

public interface IMyService
{
    string GetGreeting(string name);
}
public class MyService : IMyService
{
public string GetGreeting(string name)
{
    return $"Hello {name}!";
}

Function.cs:

public class Function1
{
    private readonly IMyService _myService;

    public Function1(IMyService myService)
    {
        _myService = myService;
    }
    [FunctionName("Function1")]
    public static async Task<List<string>> RunOrchestrator(
        [OrchestrationTrigger] IDurableOrchestrationContext context)
    {
        var outputs = new List<string>();
        outputs.Add(await context.CallActivityAsync<string>(nameof(SayHello), "Tokyo"));
        outputs.Add(await context.CallActivityAsync<string>(nameof(SayHello), "Seattle"));
        outputs.Add(await context.CallActivityAsync<string>(nameof(SayHello), "London"));
        return outputs;
    }

    [FunctionName(nameof(SayHello))]
    public string SayHello([ActivityTrigger] string name, ILogger log)
    {
        log.LogInformation("Saying hello to {name}.", name);
        return _myService.GetGreeting(name);
    }

    [FunctionName("Function1_HttpStart")]
    public async Task<HttpResponseMessage> HttpStart(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestMessage req,
        [DurableClient] IDurableOrchestrationClient starter,
        ILogger log)
    {
        string instanceId = await starter.StartNewAsync("Function1", null);

        log.LogInformation("Started orchestration with ID = '{instanceId}'.", instanceId);

        return starter.CreateCheckStatusResponse(req, instanceId);
    }
}

Output:

Functions:

        Function1_HttpStart: [GET,POST] http://localhost:7106/api/Function1_HttpStart

        Function1: orchestrationTrigger

        SayHello: activityTrigger

For detailed output, run func with --verbose flag.
[2025-04-10T08:30:53.480Z] Host lock lease acquired by instance ID '000000000000000000000000F72731CC'.
[2025-04-10T08:31:41.694Z] Executing 'Function1_HttpStart' (Reason='This function was programmatically called via the host APIs.', Id=3030762b-3b03-46cd-8c07-35a6d5096907)
[2025-04-10T08:31:41.945Z] Started orchestration with ID = '56f4203deff54838ba3443ae9d24b840'.
[2025-04-10T08:31:41.988Z] Executed 'Function1_HttpStart' (Succeeded, Id=3030762b-3b03-46cd-8c07-35a6d5096907, Duration=360ms)
[2025-04-10T08:31:42.166Z] Executing 'Function1' (Reason='(null)', Id=556a62a2-2d36-4677-a77d-a89759200dbb)
[2025-04-10T08:31:42.242Z] Executed 'Function1' (Succeeded, Id=556a62a2-2d36-4677-a77d-a89759200dbb, Duration=84ms)
[2025-04-10T08:31:42.380Z] Executing 'SayHello' (Reason='(null)', Id=41435e2d-7ef7-457e-8580-7237f532c2bf)
[2025-04-10T08:31:42.387Z] Saying hello to Tokyo.
[2025-04-10T08:31:42.393Z] Executed 'SayHello' (Succeeded, Id=41435e2d-7ef7-457e-8580-7237f532c2bf, Duration=16ms)
[2025-04-10T08:31:42.503Z] Executing 'Function1' (Reason='(null)', Id=5f714e79-8009-4ae3-b66a-4efc2eed251b)
[2025-04-10T08:31:42.533Z] Executed 'Function1' (Succeeded, Id=5f714e79-8009-4ae3-b66a-4efc2eed251b, Duration=30ms)
[2025-04-10T08:31:42.619Z] Executing 'SayHello' (Reason='(null)', Id=fae25f04-891c-4270-af67-67ee41174c23)
[2025-04-10T08:31:42.628Z] Saying hello to Seattle.
[2025-04-10T08:31:42.632Z] Executed 'SayHello' (Succeeded, Id=fae25f04-891c-4270-af67-67ee41174c23, Duration=15ms)
[2025-04-10T08:31:42.859Z] Executing 'Function1' (Reason='(null)', Id=8b237307-8ec1-4898-8159-9a00eefcbe9e)
[2025-04-10T08:31:42.871Z] Executed 'Function1' (Succeeded, Id=8b237307-8ec1-4898-8159-9a00eefcbe9e, Duration=12ms)
[2025-04-10T08:31:42.939Z] Executing 'SayHello' (Reason='(null)', Id=e16eae9b-1067-4bd7-9007-43c9275fa326)
[2025-04-10T08:31:42.944Z] Saying hello to London.
[2025-04-10T08:31:42.948Z] Executed 'SayHello' (Succeeded, Id=e16eae9b-1067-4bd7-9007-43c9275fa326, Duration=11ms)
[2025-04-10T08:31:43.031Z] Executing 'Function1' (Reason='(null)', Id=972f6a11-8eed-4d42-a1f3-e11c6f3234da)
[2025-04-10T08:31:43.047Z] Executed 'Function1' (Succeeded, Id=972f6a11-8eed-4d42-a1f3-e11c6f3234da, Duration=16ms)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.