Problems with Azure Functions v3 app importing a .NET Core 3.1 project

Viewed 1269

I building an .NET Core 3.1 Azure Functions application on my local and am trying to import a .NET Core 3.1 class library into the Functions project, but when I do, I get the following error when I run the app:

Microsoft.Azure.Functions.Extensions: Method not found: 'Microsoft.Extensions.Configuration.IConfigurationBuilder Microsoft.Azure.WebJobs.Hosting.IWebJobsConfigurationBuilder.get_ConfigurationBuilder()'. Value cannot be null. (Parameter 'provider')

I am using the ConfigurationBuilder in my Functions project:

var config = new ConfigurationBuilder()
    .SetBasePath(context.FunctionAppDirectory)
    .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
    .AddEnvironmentVariables()
    .Build();

Then I also use the configuration in a service in my library:

public MyService(IConfiguration configuration)
{
    _configuration = configuration;
}

In my Functions project I added a reference to Microsoft.Extensions.Configuration as the error indicated that it couldn't find the ConfigurationBuilder definition.

I can import a .NET Standard 2.0 project without any errors. I read that Azure Funciton V3 is compatible with .NET Core 3.1 class libraries. I have tried downgrading Microsoft.Azure.Functions.Extensions and played around with package versions, but nothing works.

Is what I am doing in my Functions project with Configuration incompatible with the .NET Core library? Why am I getting this error.

1 Answers

If you have no special needs, it is not recommended that you use a customized file to store the settings. In azure function v2&v3, settings in Values section of local.settings.json will be read as Environment variable(so I think there is no need to use customized file to store settings). Just use Environment.GetEnvironmentVariables() will be able to get the value. Generally, we only use local.settings.json for local development, and on azure portal we use configuration settings:

enter image description here

You can quickly add during deployment by Visual Studio:

enter image description here

Related