Skip to content

WebHostBuilderExtensions.UseSolutionRelativeContentRoot cannot find the solution file in the root directory #33363

Closed
@cristalink

Description

@cristalink

Microsoft.AspNetCore.TestHost.WebHostBuilderExtensions.UseSolutionRelativeContentRoot(this IWebHostBuilder builder, string solutionRelativePath, string applicationBasePath, string solutionName = "*.sln"), in aspnetcore/src/Hosting/TestHost/src/WebHostBuilderExtensions.cs, in the main branch and in latest v6.0.0-preview.4.21253.5 contains the following code:

var directoryInfo = new DirectoryInfo(applicationBasePath);
do {
...
directoryInfo = directoryInfo.Parent;
} while (directoryInfo!.Parent != null);

If the solution file is in the root directory (e.g., E:\solution.sln or \server\share\solution.sln), and if applicationBasePath points to a subfolder (E:\subfolder or E:\sub1\sub2...), the solution file won't be found because the above loop will exit at (directoryInfo!.Parent != null) since the parent of the root directory is always null.

I am not providing a test case as it requires a file in the root directory on the file system, and I am not sure what your policies are in this respect.

However, I believe the bug is pretty obvious. I also verified it with my own project.

To fix the issue, the loop condition should be as follows:

} while (directoryInfo is not null);

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesbugThis issue describes a behavior which is not expected - a bug.help wantedUp for grabs. We would accept a PR to help resolve this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions