Containerizing .NET 8 Blazor WASM breaks after update from .NET 6

75 Views Asked by At

After updating the .NET Version from 6 to 8 i can't use the deployed WebApp after starting the container and get the Exception shown down below

I have this Dockerfile now, which worked fine with .NET 6. It just differs in the SDK Version.

Dockerfile

FROM node:21-alpine3.18 as build-npm
WORKDIR /src`
COPY ["MyProj", "MyProj"]
WORKDIR /src/MyProj/NpmJS/
RUN npm install
RUN npm run build

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY --from=build-npm /src .
COPY ["otherProj", "otherProj"]
RUN dotnet restore "MyProj/MyProj.csproj"

FROM build AS publish
ENV BuildingDocker true
RUN dotnet publish "MyProj/MyProj.csproj" -c Release --no-restore -o /app/publish

FROM nginx:alpine AS final
WORKDIR /usr/share/nginx/html
COPY --from=publish /app/publish/wwwroot .
COPY MyProj/nginx.conf /etc/nginx/nginx.conf

Steps To Reproduce

Obviously you gonna need .NET 8 Workloads and Docker installed and running.

  1. Create Blazor-WebAssembly App Project with .NET 8
  2. Adjust your launchsettings.json in the Projects/Properties Folder and set:
"applicationUrl": "https://localhost:5001;http://localhost:5000"
  1. Use this Dockerfile as u wont need the NPM Part :
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY --from=build-npm /src .
COPY ["otherProj", "otherProj"]
RUN dotnet restore "MyProj/MyProj.csproj"

FROM build AS publish
ENV BuildingDocker true
RUN dotnet publish "MyProj/MyProj.csproj" -c Release --no-restore -o /app/publish

FROM nginx:alpine AS final
WORKDIR /usr/share/nginx/html
COPY --from=publish /app/publish/wwwroot .
COPY MyProj/nginx.conf /etc/nginx/nginx.conf
  1. Create nginx.conf in Project root:
events { }
http {
include mime.types;
server {
listen 5001;

    location / {
        root /usr/share/nginx/html;
        try_files $uri $uri/ /index.html =404;
    }
}
}

  1. Build dockerfile with : docker build -t MyApp .
  2. I start it via compose file but this command should do it for single proj: docker run MyApp -p 5001:5001

Navigate to localhost and Open Dev Tools

See following Error:

Uncaught TypeError: Cannot read properties of undefined (reading 'dotnet.wasm')
at blazor.webassembly.js:1:35948
at window.wasmmodulecallback (blazor.webassembly.js:1:42668)
at :1:20
at blazor.webassembly.js:1:43463
at blazor.webassembly.js:1:43478
at new Promise ()
at Object.start (blazor.webassembly.js:1:34639)
at Object.At [as start] (blazor.webassembly.js:1:59571)

Any help or guidance appreciated.

I had this Error on .NET Update locally in my Browser too. Clearing the Cache Storage fixed it but not for this Issue.

1

There are 1 best solutions below

0
Qiang Fu On

This error is because some packages are not get upgraded. After change the project version, you could try delete .bin .obj folder and rebuild.
Or if it doesn't work, create a new .Net8 project and copy your old files into it will solve the problem.