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.