2

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.

afriedman111
  • 1,925
  • 4
  • 25
  • 42

1 Answers1

1

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

Cindy Pau
  • 13,085
  • 1
  • 15
  • 27
  • So I completely removed the retreival of the environement variables and use of the ConfigurationBuilder and I still get the error. I also tried removing the offending library, creating a blank .NET Core 3.1 class library, and importing as a dependency and the error shows up. I looked at [this](https://stackoverflow.com/a/65427140/6569899) and tried changing versions but no luck. – afriedman111 Mar 24 '21 at 18:18
  • I found part of the problem. I was extending FunctionsStartup for my startup class instead of WebJobStartup. When I switched to WebStartup my projects imported. However another problem popped up. I am not able to read my request headers for my http trigger. I created a new question [here](https://stackoverflow.com/questions/66790036/functionsstartup-vs-iwebjobsstartup-problems-reading-httpheaders-on-the-request). If you have any recommendations, please let me know. – afriedman111 Mar 25 '21 at 14:46