question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Running on .NET 5.0 now results in "A valid non-empty content root must be provided"

See original GitHub issue

Describe the bug

Since upgrading to .NET 5.0, I have noticed that when deploying a product as a single file executable to Alpine Linux and running it under a rootless container via podman, I get the following error now. I really hope Kestrel does not require a directory for static content now, I use Kestrel for lightweight services and am quite happy with the 404 for any path not routed.

Unhandled exception. System.ArgumentException: A valid non-empty content root must be provided. (Parameter 'contentRootPath')
   at Microsoft.AspNetCore.Hosting.Internal.HostingEnvironmentExtensions.Initialize(IHostingEnvironment hostingEnvironment, String contentRootPath, WebHostOptions options)
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.BuildCommonServices(AggregateException& hostingStartupErrors)
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
   at NamespaceChanged.Program.RunAsync(Options options)
   at CommandLine.ParserResultExtensions.WithParsedAsync[T](ParserResult`1 result, Func`2 action)
   at NamespaceChanged.Program.Main(String[] args)
   at NamespaceChanged.Program.<Main>(String[] args)

I should mention that I do not use ASP.NET Core beyond using the Kestrel web server. I use my routing library, Routable and handle requests directly. Routable’s source is available here, but basically it does not do anything except add a handler for requests, check if the request path is matches a known route and handle it if it does, if not, it gives back control to Kestrel which until now would merrily issue a 404 (or hand off to the next handler).

The initialization looks like this:

using var server = new WebHostBuilder()
        .UseKestrel(kestrelOptions => kestrelOptions.ListenAnyIP(options.HttpPort))
        .Configure(appBuilder => appBuilder
                .UseRoutable(routable => routable
                        .AddRouting(new DefaultRouting(routable, options, profileManager))
                        .OnError(new KestrelRouting(routable) {
                                _ => _.Do((context, request, response) => {
                                        response.Status = 500;
                                        response.ClearPendingWrites();
                                        Log.Error(typeof(Program), $"A request encountered an unhandled exception.", context.Error);
                                })      
                        })      
                )       
        )       
        .Build();

using var cancellation = new CancellationTokenSource();
Console.CancelKeyPress += (_, e) => { 
        cancellation.Cancel();
        e.Cancel = true; 
};      

await server.RunAsync(cancellation.Token);

Notes

  • This does not occur when debugging on Windows using Visual Studio or running on Windows via dotnet run.
  • The executable is published as follows: dotnet publish -o publish/ -r linux-musl-x64 -c Release /p:PublishSingleFile=true /p:PublishTrimmed=true /p:IncludeNativeLibrariesForSelfExtract=true /p:IncludeAllContentForSelfExtract=true src/PROJECT_NAME

(edit: cleaned up structure a bit, added note)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
mmaguigancommented, Dec 7, 2020

@davidfowl, yep, I’m happy. Thanks guys.

1reaction
vitek-karascommented, Dec 7, 2020

My email is in my github profile. I can forward it to @davidfowl if he’s interested internally.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Could not parse the JSON file ,Error in Progam.cs asp.net ...
When I run the project, following error occurs. System.FormatException: 'Could not parse the JSON file. Error on line number '0': '' ...
Read more >
Routing in ASP.NET Core
Discover how ASP.NET Core routing is responsible for matching HTTP requests and dispatching to executable endpoints.
Read more >
Component Reference - Apache JMeter - User's Manual
Several test elements use JMeter properties to control their behaviour. These properties are normally resolved when the class is loaded.
Read more >
Chapter 2 Server Error Message Reference
Message: CHANGE REPLICATION SOURCE TO with a SOURCE_LOG_FILE clause but no SOURCE_LOG_POS clause may not be safe. The old position value may not...
Read more >
Configuration settings - Operations Manual
This page provides a complete reference to the Neo4j configuration settings.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found