Skip to content

IRazorPageFactoryProvider.CreateFactory(relativePath) should also take absolute paths #64499

@PoseidonEnergy

Description

@PoseidonEnergy

Currently, IRazorPageFactoryProvider.CreateFactory(relativePath) does not work if you pass it an absolute path to a view, like this:

var razorFactoryProvider = webApp.Services.GetRequiredService<IRazorPageFactoryProvider>();

var viewPath = "c:/dev/MyMvcSolution/MyMvcProject/Views/SomeView.cshtml"; // <-- absolute path

var factoryResult = razorFactoryProvider.CreateFactory(path);

Console.WriteLine($"Success: {factoryResult.Success}"); // Success = false

However, if you give it a path that's relative to the project, like this:

var razorFactoryProvider = webApp.Services.GetRequiredService<IRazorPageFactoryProvider>();

var viewPath = "Views/SomeView.cshtml"; // <-- relative path

var factoryResult = razorFactoryProvider.CreateFactory(path);

Console.WriteLine($"Success: {factoryResult.Success}"); // Success = true

It works fine.

Can the CreateFactory() method be modified to accept absolute file paths? Historically, RazorFileSystem could be used to convert absolute view paths to relative paths, but RazorFileSystem has been marked as obsolete in .NET 10. A quick fix for these woes would be to make IRazorPageFactoryProvider.CreateFactory() accept absolute paths.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templates

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions