Strange folder path directory error migrating from Startup.cs to Program.cs Minimal Hosting Model

91 Views Asked by At

I have moved to ASP.NET Core 6 for my MVC application and I am having a strange issue for defining my enviroment path to use when setting a file provider. My code is as follows:

var RootPath = builder.Environment.ContentRootPath;
var WebPath = builder.Environment.WebRootPath;
var applicationRoot = Path.Combine(Directory.GetParent(RootPath).ToString(), "Files");
IFileProvider physicalProvider = new PhysicalFileProvider(applicationRoot);
builder.Services.AddSingleton<IFileProvider>(physicalProvider);

When doing this my RootPath is the correct directory but applicationRoot returns the same result so its as if GetParent() is doing nothing. My old code which I was converting which has always worked is as follows:

        var applicationRoot = Path.Combine(Directory.GetParent(env.ContentRootPath).ToString(), "Files");
        IFileProvider physicalProvider = new PhysicalFileProvider(applicationRoot);
        services.AddSingleton<IFileProvider>(physicalProvider);
0

There are 0 best solutions below