Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't read from .env files using AddEnvFile(string) #2

Closed
YuKitsune opened this issue Jun 25, 2021 · 2 comments · Fixed by #3
Closed

Can't read from .env files using AddEnvFile(string) #2

YuKitsune opened this issue Jun 25, 2021 · 2 comments · Fixed by #3
Labels
bug Something isn't working

Comments

@YuKitsune
Copy link
Owner

When using the .AddEnvFile(string) method, specifying a .env file, a FileNotFoundException is always returned.

Example:

.ConfigureAppConfiguration((ctx, cfg) =>
  {
      cfg.AddEnvironmentVariables(prefix: "MyApp_");
      cfg.AddEnvFile(".env");
  })

Stacktrace:

System.IO.FileNotFoundException
The configuration file '.env' was not found and is not optional.
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.HandleException(ExceptionDispatchInfo info)
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load(Boolean reload)
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load()
   at Microsoft.Extensions.Configuration.ConfigurationRoot..ctor(IList`1 providers)
   at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()
@YuKitsune YuKitsune added the bug Something isn't working label Jun 25, 2021
@YuKitsune
Copy link
Owner Author

This is happening because by default, the FileConfigurationSource excludes dot-prefixed files, hidden files, and system files from being read into the configuration.

I've opened an issue on the .NET runtime repo asking why this is the case.
dotnet/runtime#54712

@YuKitsune
Copy link
Owner Author

Fixed in #3
The misleading error is being addressed in a PR on the .NET Core runtime PR: dotnet/runtime#54717

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant