question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can generate the file without BOM?

See original GitHub issue

Steps to reproduce

dotnet new xxx

Expected behavior

Generate the all file without BOM

Actual behavior

Generate the all file with BOM

Environment data

dotnet --info output:

Product Information: Version: 2.1.104 Commit SHA-1 hash: 48ec687460

Runtime Environment: OS Name: Windows OS Version: 10.0.16299 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\2.1.104\

Microsoft .NET Core Shared Framework Host

Version : 2.0.6 Build : 74b1c703813c8910df5b96f304b0f2b78cdf194d

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:14 (10 by maintainers)

github_iconTop GitHub Comments

4reactions
aolszowkacommented, Oct 7, 2019

FWIW at least for C# to quote from the ECMA-334 5th Edition (https://www.ecma-international.org/publications/files/ECMA-ST/ECMA-334.pdf):

  1. Conformance (PDF Page 25):
A conforming implementation of C# shall interpret characters in conformance with
the Unicode Standard. Conforming implementations shall accept Unicode source
files encoded with the UTF-8 encoding form.

7.1 Programs (PDF Page 35):

Conforming implementations shall accept Unicode source files encoded with the
UTF-8 encoding form (as defined by the Unicode standard), and transform them
into a sequence of Unicode characters. Implementations can choose to accept and
transform additional character encoding schemes (such as UTF-16, UTF-32, or
non-Unicode character mappings).

Nothing in here says that it has to contain the BOM, so if you are looking for the end all be all it will not be found in the standard…

That being said every Visual Studio version we have ever used the templates have always contained the BOM. We have commit hooks that enforce it for us internally due to some of the issues @sharwell as mentioned. For us there was a portion of code that contained some exotic characters required by a third party library that was garbled by text editors not properly respecting the fact that the file was indeed UTF-8. As he says having the BOM avoids more issues than it causes. YMMV.

3reactions
sharwellcommented, Feb 28, 2019

❗️ Source files need to be generated with BOM. Otherwise, certain editors will treat them in non-uniform manner and eventually someone will accidentally save the file with question marks (encoding error fallback character). Normally I see this in author names in files getting messed up, but recently we found a curly quote in dotnet/winforms which was incorrectly saved. These errors are easy to miss and (in many cases) hard to fix, so we create the file with BOM to avoid it altogether.

We have a secondary benefit that the BOM triggers an early exit in the automatic encoding detection algorithm in .NET, so editors like Visual Studio load files faster. It’s a small win and not really significant compared to the problem above, but I find it interesting. 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I save file in UTF-8 without BOM
In the top menu select Encoding > Convert to UTF-8 (option without BOM); Save the file. That's it, you should now have a...
Read more >
c# - Create Text File Without BOM
I'm stuck! My objective is create a file using UTF-8 as Encoding and 8859-1 as CharSet. Is this so hard to accomplish or...
Read more >
Solved: Write a file in UTF-8 without BOM - SAS Communities
Solved: Hello, I am using the following code to write a text file; DATA _NULL_; SET HAVE; FILE 'pathofthefile/nameofthefile.txt'
Read more >
Create file with UTF-8 without BOM - Help
I am trying a create a new file by Create File and Append Line activity. But the issue is it is creating a...
Read more >
services Create file in UTF8 without BOM encoding
Hi, I had a requirement in which i am convrting the UTF-BOM bytes to string and from the string I need to convert...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found