skip to Main Content

I get the � sign instead of any Cyrillic characters output by the project.
The application runs in docker. Here is my Docker file:

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 8080

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["PatiVerCore.WebApi/PatiVerCore.WebApi.csproj", "PatiVerCore.WebApi/"]
COPY ["PatiVerCore.Application/PatiVerCore.Application.csproj", "PatiVerCore.Application/"]
COPY ["PatiVerCore.Domain/PatiVerCore.Domain.csproj", "PatiVerCore.Domain/"]
COPY ["PatiVerCore.Infrastructure/PatiVerCore.Infrastructure.csproj", "PatiVerCore.Infrastructure/"]
COPY ["PatiVerCore.Persistence/PatiVerCore.Persistence.csproj", "PatiVerCore.Persistence/"]
RUN dotnet restore "./PatiVerCore.WebApi/./PatiVerCore.WebApi.csproj"
COPY . .
WORKDIR "/src/PatiVerCore.WebApi"
RUN dotnet build "./PatiVerCore.WebApi.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./PatiVerCore.WebApi.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "PatiVerCore.WebApi.dll"]

This is my docker-compose.yml file:

services:

  pativercore.webapi:
    image: ${DOCKER_REGISTRY-}pativercorewebapi
    container_name: pativer-core
    build:
      context: .
      dockerfile: PatiVerCore.WebApi/Dockerfile
    restart: always
    ports:
      - "5001:8080"
    depends_on:
      - redis_cache

  redis_cache:
    image: redis:7.4.0-alpine3.20
    container_name: redis-cache
    restart: always
    ports:
      - "6379:6379"
    command: redis-server

For example, I’m trying to display a word on the page: app.MapGet("/", () => "Приветик!");
Result

I know that the symbols are displayed correctly on the local computer in docker-desktop, but not on the Linux (Debian) server.

I tried to connect to docker and output the message echo "Приветик!" – the recording was displayed correctly

I tried to add locale to dockerfile, but it didn’t help me.

RUN apt-get update && apt-get install -y locales

# Locale
RUN sed -i -e 
  's/# ru_RU.UTF-8 UTF-8/ru_RU.UTF-8 UTF-8/' /etc/locale.gen 
   && locale-gen

ENV LANG ru_RU.UTF-8
ENV LANGUAGE ru_RU:ru
ENV LC_LANG ru_RU.UTF-8
ENV LC_ALL ru_RU.UTF-8

# +Timezone
ENV TZ Europe/Moscow
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

I feel like I’m dealing with something supernatural!

Console.WriteLine($"Кодировка: {Console.OutputEncoding.EncodingName}");
Console.WriteLine($"Кодировка: {Console.OutputEncoding.WebName}");

Result:

localetest-1  | ���������: Unicode (UTF-8)
localetest-1  | ���������: utf-8

2

Answers


  1. The editing of the source does not happen not in UTF-8, but say Windows-1251 and then the source is compiled with UTF-8, needing to substitute the corrupt bytes.

    By uXXXX escaping it will work.

    Console.WriteLine($"u041Au043Eu0434u0438u0440u043Eu0432u043Au0430...");
    

    It might be the VS remote editor using the wrong Windows encoding.

    Login or Signup to reply.
  2. I would first try adding the below to your code if you haven’t already.

    Console.OutputEncoding = Encoding.UTF8;
    

    Alternatively if you are on a Windows client connecting to the server try following these steps.
    https://superuser.com/questions/269818/change-default-code-page-of-windows-console-to-utf-8

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search