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

The configuration file 'appSettings.json' was not found ASP.NET core #157

Open
rcollette opened this issue May 4, 2018 · 6 comments
Open

Comments

@rcollette
Copy link

I am running an ASP.NET core application. My current settings file being used is appsettings.Development.json and configuration for the rest of my application is loading just fine from there.

However I am getting the message The configuration file 'appSettings.json' was not found
/Users/richardcollette/code/projectNameRoot/service/Dotted.Project.Name/bin/Debug/netcoreapp2.0/appSettings.json

It is however in the folder /Users/richardcollette/code/projectNameRoot/service/Dotted.Project.Name/bin/Debug/netcoreapp2.0/publish

Note the additional folder path of publish.

So two problems. It's not picking up the current executable path and second, it's not picking up the Development version.

I saw closed issue for this but this is ASP.net and also I have the concern about it not picking up the correct environment appsettings file.

If the rest of my application is picking up the configuration correctly, it would seem that perhaps the property accessor being used is too low level?

Is there a way to load my own list of settings (GetSection?) and pass them in to a feature FlagConfigurer?

@LuisPereiraJG
Copy link

LuisPereiraJG commented May 11, 2018

Are you getting this error whilst running on linux? Because the line here has a capital 'S', running my app in linux (.net core) causes this issue. I would say, changing it the following line of code from "appSettings" to "appsettings.json" will make it work on linux. Otherwise, you could rename your appsettings to have the weird capitalisation... but I suspect it was not intentional.

var builder = new ConfigurationBuilder().SetBasePath(AppContext.BaseDirectory).AddJsonFile("appSettings.json");

@rcollette
Copy link
Author

I'm running on Mac but the application is running in a case insensitive file system so I don't think it's related to the casing.

I'm primarily developing with ASP.NET and specifying a file name explicitly this way is generally not necessary. Is there another standard way of getting the settings without having to specify a file name?

Program.cs

public class Program
    {
        public static void Main(string[] args)
        {
            BuildWebHost(args).Run();
        }

        private static IWebHost BuildWebHost(string[] args)
        {
            var config = new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("hosting.json", true)
                .AddEnvironmentVariables("ASPNETCORE_")
                .AddCommandLine(args)
                .Build();

            return WebHost.CreateDefaultBuilder(args)
                .ConfigureLogging((context, builder) => { builder.ClearProviders(); })
                .UseConfiguration(config)
                .PreferHostingUrls(true)
                .UseStartup<Startup>()
                .Build();
        }
    }

Startup.cs

public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
            ConfigurationSection section = Configuration.GetSection("SectionName");
           //etc.
        }

        private IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
         ...
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app,
                              IHostingEnvironment env)
        {
...
        }
}

@dbrownxc
Copy link

This is happening for me on Linux. ASP.NET's built in configuration resolution expects appsettings.json (in the decompiled source) but the this library expects appSettings.json. So at least on linux, the casing is problem, especially if you develop on a case insensitive file system, like those on Windows, but deploy to Unix.

@chrissainty
Copy link

chrissainty commented Sep 21, 2018

I'm getting this error when I'm doing F5 debugging of my ASP.NET Core app in Visual Studio (Windows). I've checked the directory referenced in the exception and there is no appSettings.json. But I thought during local development the appSettings.json was read from the source root not from the bin directory?

@felipeheld
Copy link

Try running dotnet run inside .csproj dir. The Directory.GetCurrentDirectory() and .SetBasePath(builderContext.HostingEnvironment.ContentRootPath paths are apparently relative to the folder where the command is run, instead of where the Program.cs file is located at.
I usually use vscode for .NET Core, so can't tell much about how to tackle that on VS.

@V1ctorW1ll1an
Copy link

I am running an ASP.NET core application. My current settings file being used is appsettings.Development.json and configuration for the rest of my application is loading just fine from there.

However I am getting the message The configuration file 'appSettings.json' was not found /Users/richardcollette/code/projectNameRoot/service/Dotted.Project.Name/bin/Debug/netcoreapp2.0/appSettings.json

It is however in the folder /Users/richardcollette/code/projectNameRoot/service/Dotted.Project.Name/bin/Debug/netcoreapp2.0/publish

Note the additional folder path of publish.

So two problems. It's not picking up the current executable path and second, it's not picking up the Development version.

I saw closed issue for this but this is ASP.net and also I have the concern about it not picking up the correct environment appsettings file.

If the rest of my application is picking up the configuration correctly, it would seem that perhaps the property accessor being used is too low level?

Is there a way to load my own list of settings (GetSection?) and pass them in to a feature FlagConfigurer?

I was having the same error and I am using only the terminal, I just added the following group in my .csproj and it worked

<ItemGroup>
	  <None Update="appsettings.json">
	    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
	  </None>
</ItemGroup>

*.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
   
  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.7">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0-preview.5.23280.8" />
    <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.4" />
  </ItemGroup>
  
 <ItemGroup>
	  <None Update="appsettings.json">
	    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
	  </None>
	</ItemGroup>
</Project>

Even after a long time it's hard to find the solution, hope this helps someone somehow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants