ASP.NET Core – ‘Configuration.GetSection(string)’ Error in Swagger Implementation


string virDir = Configuration.GetSection("VirtualDirectory").Value;

To something like:

string virDir = app.ApplicationServices.GetRequiredService<IConfiguration>().GetSection("VirtualDirectory").Value;

Configuration refers to nothing which is why you’re getting the error. You need to pass an IConfiguration instance, or get it from the servicecontainer like i have done.

You may also want to add exta null/empty string checks to be sure your configuration is right.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top