aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

The path must be absolute. (Parameter 'root')

Open pccai opened this issue 1 year ago • 6 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Describe the bug

The path must be absolute. (Parameter 'root')

Expected Behavior

Upgrading vs before is good

Steps To Reproduce

Docker version 26.1.4, build 5650f9b Docker Desktop 4.31.1

Exceptions (if any)

在 Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root, ExclusionFilters filters) 在 Microsoft.AspNetCore.Hosting.StaticWebAssets.StaticWebAssetsLoader.<>c.<UseStaticWebAssetsCore>b__1_0(String contentRoot) 在 Microsoft.AspNetCore.StaticWebAssets.ManifestStaticWebAssetFileProvider..ctor(StaticWebAssetManifest manifest, Func2 fileProviderFactory) 在 Microsoft.AspNetCore.Hosting.StaticWebAssets.StaticWebAssetsLoader.UseStaticWebAssetsCore(IWebHostEnvironment environment, Stream manifest) 在 Microsoft.AspNetCore.Hosting.StaticWebAssets.StaticWebAssetsLoader.UseStaticWebAssets(IWebHostEnvironment environment, IConfiguration configuration) 在 Microsoft.AspNetCore.Hosting.BootstrapHostBuilder.RunDefaultCallbacks() 在 Microsoft.AspNetCore.Builder.WebApplicationBuilder.InitializeHosting(BootstrapHostBuilder bootstrapHostBuilder) 在 Microsoft.AspNetCore.Builder.WebApplicationBuilder..ctor(WebApplicationOptions options, Action1 configureDefaults) 在 Microsoft.AspNetCore.Builder.WebApplication.CreateBuilder(String[] args) 在 HY.Web.Program.Main(String[] args) 在 C:\projects\XYZ.Web\Program.cs 中: 第 41 行

.NET Version

8.0.300

Anything else?

VS17.10.2

pccai avatar Jun 24 '24 01:06 pccai

@pccai what do you mean by

Upgrading vs before is good

? Can you please provide a sample to reproduce the issue?

gfoidl avatar Jun 24 '24 15:06 gfoidl

vs2022 17.9 it works,but up to 17.10.2 is not.

pccai avatar Jun 26 '24 12:06 pccai

@pccai I notice you provided the docker version, but it seems like the stack is from Windows and VS. Is docker an important part of reproducing the issue? As @gfoidl mentioned, a sample app demonstrating the issue would be very helpful.

amcasey avatar Jun 27 '24 19:06 amcasey

cc @javiercn, who may know more about static web assets.

amcasey avatar Jun 27 '24 19:06 amcasey

I change "ASPNETCORE_ENVIRONMENT": "Development" to "ASPNETCORE_ENVIRONMENT": "Production",then it works(F5).

pccai avatar Jun 29 '24 03:06 pccai

"Container (Dockerfile)": {
  "commandName": "Docker",
  "launchBrowser": false,
  "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
  "environmentVariables": {
    "ASPNETCORE_URLS": "http://+:7001",
    "ASPNETCORE_ENVIRONMENT": "Production"
  },
  "publishAllPorts": true
},

pccai avatar Jun 29 '24 03:06 pccai

We see the same issue in our project. When running Visual Studio v17.10.x we get the "Path must be absolute" error: image

For us it seems that rolling back to Visual Studio v17.8 mitigates the issue.

We are also running a containerized app using dotnet 6, using the WSL2 based engine.

Unfortunately I can't share our solution publicly, but I'll try to create a minimal project to reproduce the issue.

AdeZwart avatar Jul 08 '24 11:07 AdeZwart

I encountered the same issue when deploying my application to Azure on Ubuntu. The issue occurs when I set the ASPNETCORE_ENVIRONMENT environment variable to Development, as shown in the Image When I switch the environment variable to Production, it works properly. Image

Microsoft Visual Studio Enterprise 2022 (64-bit) - Current Version 17.11.1 dotnet version 8

bingbing-gui avatar Nov 29 '24 06:11 bingbing-gui

Any news on that? I'm having the same issue. Can't set the Environment to Production, since some of the logic is based on that (I want developer exceptions and so on). Any workaround? I've tried setting the ContentRoot, WebRoot to specific, rooted paths - but it doesn't seem to affect the error. It's also working absolutely correctly on Rider.

OlegTopalov avatar Dec 25 '24 06:12 OlegTopalov

Small update from my side - I've removed the staticwebassets.runtime.json files (there were many of them, for different build configs), that were autogenerated by VS for some reason during the build process - and it went all right. Also, had to clean up all the .vs files, and, sort of, cleanup everything in the repo. I have no idea, why did VS think, that I need those, but they had incorrect references to appRoot folder (local) and they, of course, were not working correctly in Docker

OlegTopalov avatar Jan 10 '25 08:01 OlegTopalov

And another update - try to change the webRoot folder to something else, not wwwroot. As far, as I understood - there's some sort of VS magic, that reacts to wwwroot folder inside the project folder - VS thinks, that this folder should be copied to output no matter what and generates those staticwebassets.runtime.json files with incorrect references. Then, during WebHost.CreateDefaultBuilder it tries to resolve StaticFilesManifest -> looks for those staticwebassets.runtime.json files and sets the WebRoot to the value from those files. In Production it is not triggered, since this code is executed only in Development.

OlegTopalov avatar Jan 10 '25 14:01 OlegTopalov

I have the same problem. Waiting for a fix :-(

jwillmer avatar Jan 17 '25 10:01 jwillmer

I had the same issue, solved by specifing a correct unix path for the PhysicalFileProvider.

ander089 avatar Feb 06 '25 13:02 ander089

just delete "Blazor.Server.staticwebassets.runtime.json" from the output directory

(file will start with your project name, some thing like blabla.Blazor.Server.staticwebassets.runtime.json)

sirnicolas21 avatar Mar 05 '25 22:03 sirnicolas21

Where is the fix? Really one year?

AHailfinger avatar May 04 '25 14:05 AHailfinger