Home > Net >  asp.net core 6 The configuration file 'appsettings.json' was not found and is not optional
asp.net core 6 The configuration file 'appsettings.json' was not found and is not optional

Time:05-20

The code where I specify the path to the appsettings.json file This pic is my error message

Even though I specified the path to the appsettings file, it gives an error while creating migrations. Even if I always select the appsetting.json properties as copy always, it didn't fix it.

enter image description here

CodePudding user response:

I think you should replace the line number 10 for this line of code:

configurationManager.SetBasePath(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location))

CodePudding user response:

It was fixed when I deleted the code on line 10. new code blog:

 static public class Configuration
{
    static public string ConnectionString
    {
        get
        {
            ConfigurationManager configurationManager = new();
            //configurationManager.SetBasePath(Path.Combine(Directory.GetCurrentDirectory(),"../"));
            configurationManager.AddJsonFile("appsettings.json");


            return configurationManager.GetConnectionString("MsSqlServer");
        }
    }
}
  •  Tags:  
  • c#
  • Related