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.

File encoding is not maintained when first line of file is a conditional statement

See original GitHub issue

The file generated after doing dotnet new has a different encoding than what was in the original file for the template.

Repro:

  • Install dotnet 3.1 sdk
  • Unzip C:\Program Files\dotnet\templates\3.1.0\microsoft.dotnet.web.projecttemplates.3.1.3.1.0.nupkg and go to Web.ProjectTemplates/content/BlazorServerWeb-Csharp/
  • Verify the encoding of App.razor (It should be UTF-8 with BOM)
  • Now create a new app with dotnet new blazor
  • Open the generated App.razor and check its encoding

Expected: UTF-8 with BOM

Actual: Windows Codepage 1252

cc @phenning

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
pranavkmcommented, Mar 25, 2020

Thanks for fixing the issue @grinrag. Do you know what version of the .NET Core SDK this fix would appear in?

1reaction
phenningcommented, Jan 2, 2020

This looks like a bug when the first line of the processed file contains a conditional construct such as #if.

I just verified that either adding a blank line to the top of the file, or moving the #if to the next line as follows results in the encoding being preserved.

@*
#if (NoAuth)
<Router AppAssembly="@typeof(Program).Assembly">

@ajaybhargavb This could be used as a a workaround in the template content until the root cause of underlying bug is found and fixed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

File encoding not preserved after saving in Notepad++
It can happen that a file is saved with a certain encoding, but upon reopening it in Notepad++ it is detected with another...
Read more >
c# - UTF8 Character lost when written to file
I am suspecting that UTF8 Encoding is not the best thing to use but have yet to find a better working method. Any...
Read more >
Solved: Create a .csv file that uses UTF-8 character encod...
Solved: Hello, as the title of the subject already suggests: I want to create a .csv file that uses UTF-8 character encoding. The...
Read more >
Display problems caused by the UTF-8 BOM
Answer. If you are dealing with a file encoded in UTF-8, your display problems may be caused by the presence of a UTF-8...
Read more >
How to test whether a file uses CRLF or LF without ...
I need to periodically run a command that ensures that some text files are kept in Linux mode. Unfortunately dos2unix always modifies the...
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