1

 


Unexpected character error while building the project in a docker container


I'm creating an image of an ASP.NET CORE application that has dependency to a multiple projects not only inside the same solution but also use another class libraries in another solutions I copied the project's file, and the .sln files,it restore all the projects, however, when I attempt to build the project in a docker container an Error is encountered that prints the following message:


The Error that is Occurring, is "CS 1056"


error CS1056: Unexpected character '�'

Hint : the same error occur when i open the project using VS code

That makes sense, because there is 'obviously' a character that VS code can't decode.

After troubleshooting for a while, I found that the character causing the issue is ä (and German letter in general ü ä ß ...).




what is the way to build the project inside a docker container and avoid that error ?

I only want to build the project in a docker container correctly by the way if I build the project using powershell in Host windows OS it builds correctly with no problem .

Thanks

JΛYDΞV
  • 8,532
  • 3
  • 51
  • 77
Dark Storm
  • 187
  • 4
  • 10
  • Check the [file encoding](https://stackoverflow.com/a/3418952) to make sure it is compatible with the characters within it (UTF-8 is usually a good choice). – NightOwl888 May 25 '22 at 12:18
  • it's UTF-16 encoding , the unexpected character is ä the german letter – Dark Storm May 25 '22 at 12:27
  • You may not have an issue. It is just the way VS is displaying the character and application may work. The VS settings may be using a different encoding scheme than the encoding used in the project. – jdweng May 25 '22 at 12:27
  • i was thinking that way but i took a new copy of the project never opened with vscode but while building the docker image it throw the same errors while building – Dark Storm May 25 '22 at 12:30
  • Are you sure it is UTF-16? Character 0x00 to 0x7F are the same for all encoding. The character 0x80 to 0xFF are mapped to unicode characters and are different depending on encoding. The reason for encoding is to save memory so encoding uses one byte instead of two bytes for the character 0x80 to 0xFF. If you were using UTF-16 than you should not get an error. – jdweng May 25 '22 at 12:32
  • sorry the encoding is : Western European (Windows) - CodePage 1252 – Dark Storm May 25 '22 at 12:44
  • Okay, well you figured it out while I was authoring the answer. Lol, glad you got it. – JΛYDΞV May 25 '22 at 12:54
  • the guy that edited the question changed the context , you have to watch the question title before you do anything please ... – Dark Storm May 26 '22 at 07:44

1 Answers1

2

Whether you are in VS Code, or you are in docker the same simple solution applies. Also, it is important to note, a quick google search would have produced ample enough information to have solved this issue.

So this is Computer Science 101, its fundamental to all programming languages, and systems. You have to configure your project to use the same encoding as your system, which in this case is Linux.

DOCKER = LINUX SHELL

POWERSHELL = Well, just Powershell.

Docker & Powershell, are both shells, but two totally different system-environments. You will need to configure Docker, and the SSH client your using to remotely work in docker to use the same encoding as your project.

You said you don't care about VS Code so I guess, your using a different SSH client?

In this case it is German characters causing the issue, and because your using a Microsoft tech-stack (i.e. C#, ASP.NET, etc...) its going to be a CP.

According to Microsoft

...CP1252 will cover both English (which obviously you need, and German alphabets (also included is French).
JΛYDΞV
  • 8,532
  • 3
  • 51
  • 77
  • i am looking fo solution to build the project in a docker container not to use VSCODE but thanks by the way ................ – Dark Storm May 27 '22 at 08:03
  • 1
    @Davidcrage [Based on the hints of this answer](https://stackoverflow.com/a/43005149/7687666), I think we can add the [Microsoft.NETCore.Compilers package](https://www.nuget.org/packages/Microsoft.NETCore.Compilers/) to the project and give it a try. – Jason Pan May 27 '22 at 10:04
  • 1
    @jason , yep i already installed the dotnet sdk on the wscore image instead of using the sdk image and it worked .. even i can not figure out the missing piece in the sdk image why it does show me the error . – Dark Storm May 27 '22 at 10:50
  • You tagged it VS Code – JΛYDΞV May 27 '22 at 18:16
  • And its the same answer regardless – JΛYDΞV May 27 '22 at 18:16
  • Also, the character `?` comes from the fact, VS Code doesn't recognize the encoding...... – JΛYDΞV May 27 '22 at 18:18