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.

ASP.NET Core hosted Blazor app fails to run in Docker

See original GitHub issue

Repro steps:

  • Create a new Blazor (ASP.NET Core hosted) app with the Preview 4 bits
  • Build and run - it works
  • Right click, Add Docker support (Linux)
  • Build and run on Docker Linux

Actual result:

Unhandled Exception: System.ArgumentException: The directory name  is invalid.
Parameter name: path
   at System.IO.FileSystemWatcher.CheckPathValidity(String path)
   at System.IO.FileSystemWatcher..ctor(String path)
   at Microsoft.AspNetCore.Builder.AutoRebuildExtensions.WatchFileSystem(BlazorConfig config, Action onWrite)
   at Microsoft.AspNetCore.Builder.BlazorApplicationBuilderExtensions.UseBlazor(IApplicationBuilder app, BlazorOptions options)
   at BlazorDocker.Server.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env) in C:\Users\daroth\Source\Repos\BlazorDocker\BlazorDocker.Server\Startup.cs:line 43
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Hosting.Internal.ConventionBasedStartup.Configure(IApplicationBuilder app)
   at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
   at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.StartAsync(CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken token, String startupMessage)
   at Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken token, String startupMessage)
   at Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken token)
   at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(IWebHost host)
   at BlazorDocker.Server.Program.Main(String[] args) in C:\Users\daroth\Source\Repos\BlazorDocker\BlazorDocker.Server\Program.cs:line 11

More repro steps:

  • Disable Blazor auto-build by adding <BlazorRebuildOnFileChange>false</BlazorRebuildOnFileChange> to the client project file.
  • Build and run the app

Actual result:

Unhandled Exception: System.ArgumentException: The path must be absolute.
   at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root, ExclusionFilters filters)
Parameter name: root
   at Microsoft.AspNetCore.Builder.BlazorApplicationBuilderExtensions.UseBlazor(IApplicationBuilder app, BlazorOptions options)
   at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root, ExclusionFilters filters)
   at BlazorDocker.Server.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env) in C:\Users\daroth\Source\Repos\BlazorDocker\BlazorDocker.Server\Startup.cs:line 43
   at Microsoft.AspNetCore.Builder.BlazorApplicationBuilderExtensions.UseBlazor(IApplicationBuilder app, BlazorOptions options)
--- End of stack trace from previous location where exception was thrown ---
   at BlazorDocker.Server.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env) in C:\Users\daroth\Source\Repos\BlazorDocker\BlazorDocker.Server\Startup.cs:line 43
   at Microsoft.AspNetCore.Hosting.Internal.ConventionBasedStartup.Configure(IApplicationBuilder app)
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
   at Microsoft.AspNetCore.Hosting.Internal.ConventionBasedStartup.Configure(IApplicationBuilder app)
   at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
   at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
   at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
crit: Microsoft.AspNetCore.Hosting.Internal.WebHost[6]
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.StartAsync(CancellationToken cancellationToken)
      Application startup exception
   at Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken token, String startupMessage)
System.ArgumentException: The path must be absolute.
Parameter name: root
   at Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken token, String startupMessage)
   at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root, ExclusionFilters filters)
   at Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken token)
   at Microsoft.AspNetCore.Builder.BlazorApplicationBuilderExtensions.UseBlazor(IApplicationBuilder app, BlazorOptions options)
   at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(IWebHost host)
   at BlazorDocker.Server.Program.Main(String[] args) in C:\Users\daroth\Source\Repos\BlazorDocker\BlazorDocker.Server\Program.cs:line 11
   at BlazorDocker.Server.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env) in C:\Users\daroth\Source\Repos\BlazorDocker\BlazorDocker.Server\Startup.cs:line 43
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Hosting.Internal.ConventionBasedStartup.Configure(IApplicationBuilder app)
   at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
   at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:19 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
mkArtakMSFTcommented, Aug 12, 2019

This will be fixed soon.

2reactions
rchandecommented, Jul 3, 2019

@RealTadango In my case, this was happening because we were calling “UseContentRoot” in a way that could cause it to be something other than the location of our assembly. Changing it to:

.UseContentRoot(Path.GetDirectoryName(typeof(Program).Assembly.Location))

seems to help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't access Blazor app in Docker container
I fixed the issue. The problem was my Program.cs. You don't need a Host, you need a WebHost: using Microsoft.AspNetCore; using Microsoft.
Read more >
Why isn't my ASP.NET Core app in Docker working?
So when you run an ASP.NET Core app locally, and navigate to http://localhost:5000 in your browser, everything works, because everything is all ...
Read more >
Troubleshooting an ASP.NET Core App Running in Docker
I was recently standing up a new ASP.NET Core application running in Docker, and I was seeing some very strange behaviour.
Read more >
Host and deploy ASP.NET Core Blazor WebAssembly
Learn how to host and deploy Blazor WebAssembly using ASP.NET Core, Content Delivery Networks (CDN), file servers, and GitHub Pages.
Read more >
Containerising a Blazor WebAssembly App
In this post, I show how to containerise a Blazor WebAssembly App using Docker. Highlighting the different requirements when compared to ...
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