I have a Blazor dotnet project that depends on the NuGet package QuickGrid v9.0.1. When I run my project in the browser, I see it is able to fetch
http://localhost:5157/_framework/blazor.web.js and http://localhost:5157/_content/Microsoft.AspNetCore.Components.QuickGrid/QuickGrid.razor.js successfully.
However, when I attempt running it in a docker container, the fetch to QuickGrid.razor.js returns a 404. The project executable itself logs this exception:
Unhandled exception rendering component: Failed to fetch dynamically imported module: http://localhost:64565/_content/Microsoft.AspNetCore
.Components.QuickGrid/QuickGrid.razor.js
TypeError: Failed to fetch dynamically imported module: http://localhost:64565/_content/Microsoft.AspNetCore.Components.QuickGrid/QuickGrid.razo
r.js
Microsoft.JSInterop.JSException: Failed to fetch dynamically imported module: http://localhost:64565/_content/Microsoft.AspNetCore.Compone
nts.QuickGrid/QuickGrid.razor.js
TypeError: Failed to fetch dynamically imported module: http://localhost:64565/_content/Microsoft.AspNetCore.Components.QuickGrid/QuickGrid.razo
r.js
at Microsoft.JSInterop.JSRuntime.InvokeAsync[TValue](Int64 targetInstanceId, String identifier, Object[] args)
at Microsoft.AspNetCore.Components.QuickGrid.QuickGrid`1.OnAfterRenderAsync(Boolean firstRender)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
fail: Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]
Unhandled exception in circuit 'd84-wSUQMbiaIh3fuwlO_MD-6kRNXP4L9fDB-r9IrAw'.
For reference, here's my Dockerfile. You'll see that it's modified from the Visual Studio-generated template, mainly because I have 2 projects in my solution, and I would like them to run in the same container.
# This stage is used when running from VS in fast mode (Default for Debug configuration)
FROM mcr.microsoft/dotnet/aspnet:9.0-nanoserver-1809 AS base
WORKDIR /app
EXPOSE 5088
EXPOSE 5089
EXPOSE 5157
EXPOSE 5158
EXPOSE 8080
# This stage is used to build the service project
FROM mcr.microsoft/dotnet/sdk:9.0-nanoserver-1809 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["Server/Server.csproj", "Server/"]
COPY ["Client/Client.csproj", "Client/"]
RUN dotnet restore "./Server/Server.csproj"
RUN dotnet restore "./Client/Client.csproj"
COPY . .
WORKDIR "/src/Server"
RUN dotnet build "./Server.csproj" -c %BUILD_CONFIGURATION% -o /app/build
WORKDIR "/src/Client"
RUN dotnet build "./Client.csproj" -c %BUILD_CONFIGURATION% -o /app/build
# This stage is used to publish the service project to be copied to the final stage
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
WORKDIR "/src/Server"
RUN dotnet publish "./Server.csproj" -c %BUILD_CONFIGURATION% -o /app/publish /p:UseAppHost=false
WORKDIR "/src/Client"
RUN dotnet publish "./Client.csproj" -c %BUILD_CONFIGURATION% -o /app/publish /p:UseAppHost=false
# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration)
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
COPY Server/ocb.db .
ENTRYPOINT ["dotnet", "Client.dll"]
I can see the QuickGrid.razor.js file when I peek inside the publish docker stage living in this directory:
`/src/Client/.nuget/packages/microsoft.aspnetcoreponents.quickgrid/9.0.1/staticwebassets`, however, it's not being copied over to the final stage. When I attempt to copy it myself with commands such as
`COPY --from=publish /src/Client/.nuget/packages/microsoft.aspnetcoreponents.quickgrid/9.0.1/staticwebassets wwwroot/Microsoft.AspNetCore.Components.QuickGrid`,
`COPY --from=publish /src/Client/.nuget/packages/microsoft.aspnetcoreponents.quickgrid/9.0.1/staticwebassets wwwroot`,
`COPY --from=publish /src/Client/.nuget/packages/microsoft.aspnetcoreponents.quickgrid/9.0.1/staticwebassets /src/Client/.nuget/packages/microsoft.aspnetcoreponents.quickgrid/9.0.1/staticwebassets`,
`COPY --from=publish /src/Client/.nuget/packages/microsoft.aspnetcoreponents.quickgrid/9.0.1/staticwebassets wwwroot/_content/Microsoft.AspNetCore.Components.QuickGrid/QuickGrid.razor.js`,
and
COPY --from=publish /src/Client/.nuget/packages/microsoft.aspnetcoreponents.quickgrid/9.0.1/staticwebassets _content/Microsoft.AspNetCore.Components.QuickGrid/QuickGrid.razor.js
,
I get the same error. I don't know what destination folder to put it in because I don't know where QuickGrid is expecting it to be or what the directory _content
is an alias for.
It's especially strange that in the container, it's able to fetch blazor.web.js just fine. How can I ensure that static files originating from NuGet packages make the transition over to the container?
Similar Question: Load JS file with custom razor component in Blazor app, the answer to this question assumes a .js file with a static path that lives inside the project directory, not one originating from a NuGet package.
I have a Blazor dotnet project that depends on the NuGet package QuickGrid v9.0.1. When I run my project in the browser, I see it is able to fetch
http://localhost:5157/_framework/blazor.web.js and http://localhost:5157/_content/Microsoft.AspNetCore.Components.QuickGrid/QuickGrid.razor.js successfully.
However, when I attempt running it in a docker container, the fetch to QuickGrid.razor.js returns a 404. The project executable itself logs this exception:
Unhandled exception rendering component: Failed to fetch dynamically imported module: http://localhost:64565/_content/Microsoft.AspNetCore
.Components.QuickGrid/QuickGrid.razor.js
TypeError: Failed to fetch dynamically imported module: http://localhost:64565/_content/Microsoft.AspNetCore.Components.QuickGrid/QuickGrid.razo
r.js
Microsoft.JSInterop.JSException: Failed to fetch dynamically imported module: http://localhost:64565/_content/Microsoft.AspNetCore.Compone
nts.QuickGrid/QuickGrid.razor.js
TypeError: Failed to fetch dynamically imported module: http://localhost:64565/_content/Microsoft.AspNetCore.Components.QuickGrid/QuickGrid.razo
r.js
at Microsoft.JSInterop.JSRuntime.InvokeAsync[TValue](Int64 targetInstanceId, String identifier, Object[] args)
at Microsoft.AspNetCore.Components.QuickGrid.QuickGrid`1.OnAfterRenderAsync(Boolean firstRender)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
fail: Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]
Unhandled exception in circuit 'd84-wSUQMbiaIh3fuwlO_MD-6kRNXP4L9fDB-r9IrAw'.
For reference, here's my Dockerfile. You'll see that it's modified from the Visual Studio-generated template, mainly because I have 2 projects in my solution, and I would like them to run in the same container.
# This stage is used when running from VS in fast mode (Default for Debug configuration)
FROM mcr.microsoft/dotnet/aspnet:9.0-nanoserver-1809 AS base
WORKDIR /app
EXPOSE 5088
EXPOSE 5089
EXPOSE 5157
EXPOSE 5158
EXPOSE 8080
# This stage is used to build the service project
FROM mcr.microsoft/dotnet/sdk:9.0-nanoserver-1809 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["Server/Server.csproj", "Server/"]
COPY ["Client/Client.csproj", "Client/"]
RUN dotnet restore "./Server/Server.csproj"
RUN dotnet restore "./Client/Client.csproj"
COPY . .
WORKDIR "/src/Server"
RUN dotnet build "./Server.csproj" -c %BUILD_CONFIGURATION% -o /app/build
WORKDIR "/src/Client"
RUN dotnet build "./Client.csproj" -c %BUILD_CONFIGURATION% -o /app/build
# This stage is used to publish the service project to be copied to the final stage
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
WORKDIR "/src/Server"
RUN dotnet publish "./Server.csproj" -c %BUILD_CONFIGURATION% -o /app/publish /p:UseAppHost=false
WORKDIR "/src/Client"
RUN dotnet publish "./Client.csproj" -c %BUILD_CONFIGURATION% -o /app/publish /p:UseAppHost=false
# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration)
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
COPY Server/ocb.db .
ENTRYPOINT ["dotnet", "Client.dll"]
I can see the QuickGrid.razor.js file when I peek inside the publish docker stage living in this directory:
`/src/Client/.nuget/packages/microsoft.aspnetcoreponents.quickgrid/9.0.1/staticwebassets`, however, it's not being copied over to the final stage. When I attempt to copy it myself with commands such as
`COPY --from=publish /src/Client/.nuget/packages/microsoft.aspnetcoreponents.quickgrid/9.0.1/staticwebassets wwwroot/Microsoft.AspNetCore.Components.QuickGrid`,
`COPY --from=publish /src/Client/.nuget/packages/microsoft.aspnetcoreponents.quickgrid/9.0.1/staticwebassets wwwroot`,
`COPY --from=publish /src/Client/.nuget/packages/microsoft.aspnetcoreponents.quickgrid/9.0.1/staticwebassets /src/Client/.nuget/packages/microsoft.aspnetcoreponents.quickgrid/9.0.1/staticwebassets`,
`COPY --from=publish /src/Client/.nuget/packages/microsoft.aspnetcoreponents.quickgrid/9.0.1/staticwebassets wwwroot/_content/Microsoft.AspNetCore.Components.QuickGrid/QuickGrid.razor.js`,
and
COPY --from=publish /src/Client/.nuget/packages/microsoft.aspnetcoreponents.quickgrid/9.0.1/staticwebassets _content/Microsoft.AspNetCore.Components.QuickGrid/QuickGrid.razor.js
,
I get the same error. I don't know what destination folder to put it in because I don't know where QuickGrid is expecting it to be or what the directory _content
is an alias for.
It's especially strange that in the container, it's able to fetch blazor.web.js just fine. How can I ensure that static files originating from NuGet packages make the transition over to the container?
Similar Question: Load JS file with custom razor component in Blazor app, the answer to this question assumes a .js file with a static path that lives inside the project directory, not one originating from a NuGet package.
Share Improve this question edited Mar 22 at 4:41 jam j 6261 gold badge2 silver badges19 bronze badges asked Mar 21 at 20:32 twhatm9twhatm9 275 bronze badges1 Answer
Reset to default 0My copy command was close but off
COPY --from=publish /src/Client/.nuget/packages/microsoft.aspnetcoreponents.quickgrid/9.0.1/staticwebassets /app/wwwroot/_content/Microsoft.AspNetCore.Components.QuickGrid/
did the trick.