My case is that the .csproj declaration generated by Unity is always UTF-16, while the encoding is UTF-8, which leads to the problem in the question.
The solution is to go to VSCode and uncheck preferCSharpExtension.
In VSCode, Ctrl + Shift + P — "Open User Settings" — Search for "preferCSharpExtension" — Uncheck both User and Workspace settings.