Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible Bug - System.ArgumentException : The content root '' does not exist #7063

Closed
rguthriemsft opened this issue Jun 14, 2018 · 5 comments
Labels
Source - Docs.ms Docs Customer feedback via GitHub Issue

Comments

@rguthriemsft
Copy link

I am seeing an issue when I try to create an integration test with a custom WebApplicationFactory. I get the error below but what is puzzling is the path is missing one folder in the path and I don't know where this value is coming from. It should be '/Users/richardguthrie/go/src/github.com/Azure-Samples/openhack-devops-team/apis/poi/tests/IntegrationTests'

The code is checked in at: https://github.com/Azure-Samples/openhack-devops-team/tree/unit_test3

Is this a bug or am I missing something when I try to init the webhost that would fix this? My intent is to spin up a server locally with in memory db to run the integration test. This happens when I run Debug Test from within VSCode using C# extension.

[xUnit.net 00:00:26.3698120] IntegrationTests.POIIntegrationTests.Get_EndpointsReturnSuccessAndCorrectContentType(url: "/api/poi/") [FAIL]
[xUnit.net 00:00:26.3715660] System.ArgumentException : The content root '/Users/richardguthrie/go/src/github.com/Azure-Samples/openhack-devops-team/apis/poi/IntegrationTests' does not exist.
[xUnit.net 00:00:26.3716860] Parameter name: contentRootPath
[xUnit.net 00:00:26.3732960] Stack Trace:
[xUnit.net 00:00:26.3754940] at Microsoft.AspNetCore.Hosting.Internal.HostingEnvironmentExtensions.Initialize(IHostingEnvironment hostingEnvironment, String contentRootPath, WebHostOptions options)
[xUnit.net 00:00:26.3756430] at Microsoft.AspNetCore.Hosting.WebHostBuilder.BuildCommonServices(AggregateException& hostingStartupErrors)
[xUnit.net 00:00:26.3757000] at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
[xUnit.net 00:00:26.3758120] at Microsoft.AspNetCore.TestHost.TestServer..ctor(IWebHostBuilder builder, IFeatureCollection featureCollection)
[xUnit.net 00:00:26.3758790] at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory1.CreateServer(IWebHostBuilder builder) [xUnit.net 00:00:26.3760500] at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory1.EnsureServer()
[xUnit.net 00:00:26.3761230] at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory1.CreateDefaultClient(DelegatingHandler[] handlers) [xUnit.net 00:00:26.3762400] at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory1.CreateClient

@guardrex
Copy link
Collaborator

Hello @rguthriemsft You might need to set the content root path explicitly with UseSolutionRelativeContentRoot. See: https://docs.microsoft.com/aspnet/core/test/integration-tests#how-the-test-infrastructure-infers-the-app-content-root-path

Beyond that, the docs repo primarily handles docs issues ... we aren't really staffed to handle support requests. You'd probably need to open this on the Home repo (https://github.com/aspnet/Home/issues) for help or try Stack Overflow. Certainly if you run into a docs problem that would have helped, please let us know so we can update the content.

@guardrex guardrex added Source - Docs.ms Docs Customer feedback via GitHub Issue P4 labels Jun 14, 2018
@guardrex guardrex added this to the Backlog milestone Jun 14, 2018
@guardrex guardrex removed this from the Backlog milestone Jun 14, 2018
@mattfrear
Copy link

@rguthriemsft FWIW I have the exist same error, and google has lead me to the only other person on the planet who has seen the same error. In my case the Content root is also missing a tests folder.

I've followed the article which guardrex suggested, and in my case adding builder.UseContentRoot(".") fixes the problem. Working code:

    public class ProviderStateApiFactory : WebApplicationFactory<ProviderStateApi>
    {
        protected override IWebHostBuilder CreateWebHostBuilder()
        {
            return WebHost.CreateDefaultBuilder()
                .UseStartup<ProviderStateApi>();
        }

        protected override void ConfigureWebHost(IWebHostBuilder builder)
        {
            builder.UseContentRoot(".");
            base.ConfigureWebHost(builder);
        }
    }

@cnblogs-dudu
Copy link

Found a simpler workaround.

public class BlogAppFactory : WebApplicationFactory<Startup>
{
    protected override IWebHostBuilder CreateWebHostBuilder()
    {
        return WebHost.CreateDefaultBuilder()
            .UseStartup<TestStartup>();
    }
}

@arkiaconsulting
Copy link

@maurei @mattfrear workaround works for me with Net Core 3.1.

@Levridge-Tory
Copy link

The workaround from @mattfrear works for me also with Net Core 3.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Source - Docs.ms Docs Customer feedback via GitHub Issue
Projects
None yet
Development

No branches or pull requests

6 participants