dotnet / dotnet/aspnetcore

`IRazorPageFactoryProvider.CreateFactory(relativePath)` should also take absolute paths

Open
#64,499 0 comments 0 reactions 0 assignees View on GitHub
area-mvc
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

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

```c#
var razorFactoryProvider = webApp.Services.GetRequiredService();

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:

```c#
var razorFactoryProvider = webApp.Services.GetRequiredService();

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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.