The bigger problem is that this approach will not work at all in Azure, since you won't know the file path in advance.
The solution seems to be to move the XML file to the wwwroot and define the pathToDoc in Startup.cs in the constructor:
public class Startup
{
private string pathToDoc;
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddEnvironmentVariables();
Configuration = builder.Build();
pathToDoc = env.WebRootPath + @"\docweb1.xml";
}
This is working for me on Azure.