plz i need help

Mohamed Laaboudi 0 Reputation points
2024-06-19T01:00:54.74+00:00

An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider. Error: Failed to load configuration from file 'C:\Users\Administrator\Desktop\frontapi\appsettings.json'.

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,535 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Jiale Xue - MSFT 41,426 Reputation points Microsoft Vendor
    2024-06-19T03:38:55.47+00:00

    Hi @Mohamed Laaboudi , Welcome to Microsoft Q&A,

    Make sure the file path is correct. Especially on Windows, the path separator should be a backslash (). Check that the appsettings.json actually exists in the specified path. Make sure that the user running the application has permission to read the appsettings.json file.

    Check your application code to make sure the configuration file is loaded with the correct logic. For example:

    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }
    
        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureAppConfiguration((hostingContext, config) =>
                {
                    config.SetBasePath(Directory.GetCurrentDirectory());
                    config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
                    config.AddEnvironmentVariables();
                    if (args != null)
                    {
                        config.AddCommandLine(args);
                    }
                })
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                });
    }
    
    

    Best Regards,

    Jiale


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments