configure azure function to use json file

Mj 0 Reputation points
2023-10-12T02:51:29.3833333+00:00

using ConfigureAppConfiguration of Startup calss but raises error that couldn't find any logic answer to solve

public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
        {            
                base.ConfigureAppConfiguration(builder);
                FunctionsHostBuilderContext context = builder.GetContext();
                builder.ConfigurationBuilder
                    .AddJsonFile(Path.Combine(context.ApplicationRootPath, "appsetting.json"), optional: true, reloadOnChange: false)
                    .AddJsonFile(Path.Combine(context.ApplicationRootPath, $"appsetting.{context.EnvironmentName}.json"), optional: true, reloadOnChange: false)
                    .AddEnvironmentVariables();

            }
public override void Configure(IFunctionsHostBuilder builder)
        {            
                builder.Services.AddOptions<AppSettingsConfigurationOptions>()
                    .Configure<IConfiguration>((settings, configuration) =>
                    { configuration.GetSection("AppSettings").Bind(settings); 
                    });

}
tried different way but every time same couple of errors while Microsoft.Extensions.Configuration.Abstractions has been installed with same version
here is error:
Error building configuration in an external startup class.

Error building configuration in an external startup class. LicenseMNG: Could not load file or assembly 'Microsoft.Extensions.Configuration.Abstractions, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9'. The system cannot find the file specified.

A host error has occurred during startup operation '1bd4'.

Microsoft.Azure.WebJobs.Script: Error building configuration in an external startup class. LicenseMNG: Could not load file or assembly 'Microsoft.Extensions.Configuration.Abstractions, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9'. The system cannot find the file specified.

Value cannot be null. (Parameter 'provider')

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,911 questions
Microsoft Security | Intune | Configuration Manager | Other
{count} votes

1 answer

Sort by: Most helpful
  1. navba-MSFT 27,540 Reputation points Microsoft Employee Moderator
    2023-10-12T07:12:46.2033333+00:00

    @Mj Welcome to Microsoft Q&A Forum, Thank you for posting your query here!

    I understand that you are encountering an error that says Error building configuration in an external startup class. LicenseMNG: Could not load file or assembly 'Microsoft.Extensions.Configuration.Abstractions, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9'. The system cannot find the file specified.

    Please try the following action plan and let me know if that helps:

    1.Where is your startup class being inherited from ? Try Changing the Startup to inherit from FunctionsStartup rather than WebJobsStartup. See below:

    [assembly: FunctionsStartup(typeof(Startup))]
    
    public class Startup : FunctionsStartup { ... 
    
    public override void Configure(IFunctionsHostBuilder builder)
        {
    
            var configuration = new ConfigurationBuilder()
                .AddEnvironmentVariables()
                .Build();
    
            builder.Services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
    
            builder.Services.AddHttpClient();
    
            ...
         }
    
    1. Firstly make sure that you are using most recent version of azure-functions-core-tools

    3.Please check and ensure that you are using Azure Function v4.

    4.Also ensure you have <AzureFunctionsVersion>v4</AzureFunctionsVersion> within csproj and if the App is already deployed to Azure then within the App Settings have FUNCTIONS_EXTENSION_VERSION set to ~4

    5.From this nuget link try installing the 7.0.0.0 version of Microsoft.Extensions.Configuration.Abstractions package. And remove all the other references of this package from your project.
    6.If you still get error with 7.0.0.0 version, Try with 6.0.0.0 version of this package from this nuget link.
    7.Remove the version from the csproj for this assembly as shown below:

    <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" />
    

    8.Try adding the below to your csproj file:

    <PropertyGroup>
        <_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
    </PropertyGroup>
    

    9.Also have the below setting within your csproj file:

    <ItemGroup>
      <Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext"/>
    </ItemGroup>
    

    10.Please try downgrading ALL of Microsoft.Extensions.* to 6.0.0 and check if that helps.

    11.Was this app recently upgraded to to .NET 7 ? Is this an isolated model ? See here and here.

    If none of the above action plan helps, please let me know. I would be happy to assist you further.

    Sharing some of the links where similar issue was reported:
    https://stackoverflow.com/questions/64809716/could-not-load-file-or-assembly-microsoft-extensions-configuration-abstractions
    https://github.com/Azure/azure-functions-core-tools/issues/2304
    https://stackoverflow.com/questions/43995432/could-not-load-file-or-assembly-microsoft-extensions-dependencyinjection-abstrac
    https://stackoverflow.com/questions/74808187/could-not-load-file-or-assembly-microsoft-extensions-configuration-abstractions

    https://stackoverflow.com/questions/74470489/system-io-filenotfoundexception-could-not-load-file-or-assembly-microsoft-exte

    **

    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    1 person found this answer helpful.
    0 comments No comments

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.