In this azure tutorial, we will discuss how to fix the error, Error CS1061 ‘IConfigurationBuilder’ does not contain a definition for ‘AddEnvironmentVariables’. This error I got while working with Azure function to access the app settings using the Visual Studio.
Table of Contents
Error CS1061 ‘IConfigurationBuilder’ does not contain definition for ‘AddEnvironmentVariables’
I was working with the Azure Functions and was trying to access application settings using Visual Studio, I got the error.
- response_type ‘id_token’ is not enabled for the application
- The term ‘get-azuresubscription’ is not recognized
The Azure function was like below
public static class MyProductHTTPFunction
{
[FunctionName("MyProductHTTPFunction")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log, ExecutionContext context)
{
log.LogInformation("MyProductHTTPFunction function processed a request.");
var configurationBuilder = new ConfigurationBuilder()
.SetBasePath(context.FunctionAppDirectory)
.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
string myappsettingsValue = configurationBuilder["appsettingkey"];
You can see here

The exact error message was as below
Error CS1061 ‘IConfigurationBuilder’ does not contain a definition for ‘AddEnvironmentVariables’ and no accessible extension method ‘AddEnvironmentVariables’ accepting a first argument of type ‘IConfigurationBuilder’ could be found (are you missing a using directive or an assembly reference?)
Error CS1061 ‘IConfigurationBuilder’ does not contain definition for ‘AddEnvironmentVariables’ [Solved]
To fix this error, we need to add few NuGet Packages. To do that follow the below steps
Right click on the Project and click on the Manage NuGet Packages

You need to add the Microsoft.Extensions.Configuration.EnvironmentVariables package like below. Search for the same package and click on the Install button.

Same way, you can add the Nuget package Microsoft.Extensions.Configuration.UserSecrets.

The above are the two packages you need to install, if you are getting the error due to AddEnvironmentVariables().
There is a chance you might get the same error for the SetBasePath() method. In that case, you need to add one Nuget package in the same way as above i.e Microsoft.Extensions.Configuration.Abstractions.

This will fix the issue in case of SetBasePath() method.
Also, You might get the same error for the AddJsonFile() method. To fix the issue you need to install two Nuget Packages that are Microsoft.Extensions.Configuration.FileExtensions and Microsoft.Extensions.Configuration.Json.

And also, the below package

You may also like following the below Articles
- No match was found for the specified search criteria and module names ‘AzTable’
- CS1061 C# ‘HttpRequest’ does not contain a definition for ‘Content’ and no accessible extension method ‘Content’ accepting a first argument of type ‘HttpRequest’ could be found
- The Term ‘Connect-AzureRmAccount’ is Not Recognized
- The term ‘register-AzureProvider’ is not recognized as the name of a cmdlet
- The term ‘Select-AzureSubscription’ is not recognized as the name of a cmdlet
Wrapping Up
In this article, we have discussed how to fix the error Error CS1061 ‘IConfigurationBuilder’ does not contain definition for ‘AddEnvironmentVariables. The above solution will also fix the below issues
- iconfigurationbuilder does not contain a definition for addenvironmentvariables
- addenvironmentvariables not found
- ‘configurationbuilder’ does not contain a definition for ‘setbasepath’
- addenvironmentvariables
- iconfiguration does not contain a definition for get
- configurationbuilder addenvironmentvariables not found
- ‘configurationbuilder’ does not contain a definition for ‘addjsonfile’
- iconfigurationbuilder addenvironmentvariables
- ‘configurationbuilder’ does not contain a definition for ‘setbasepath’ and no accessible extension method ‘setbasepath’ accepting a first argument of type ‘configurationbuilder’ could be found
- ‘configurationbuilder’ does not contain a definition for ‘setbasepath’ and no accessible extension method ‘setbasepath’ accepting a first argument of type ‘configurationbuilder’ could be found (are you missing a using directive or an assembly reference?)
Hope it will help you to fix your issue !!!