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.

NativeVersionInfo emits RC script in incorrect encoding

See original GitHub issue

Attempting to use Nerdbank.GitVersioning’s NativeVersionInfo to generate non-version for native Windows DLLs can result in malformed version resources when special characters such as © and ® are used. Generally, the special character is preceded by an unprintable or garbage character.

Crude Diagnosis: File.WriteAllText() writes text files in .NET’s preferred UTF-8, no BOM, which I think leads the output file to basically be RC’s expected ANSI save for the rare multi-byte special character, which is rendered as two separate ANSI characters rather than a single 2 byte UTF-8 character.

I think there are at least three possible improvements:

  1. Change Utilities.FileOperationWithRetry(() => File.WriteAllText(this.OutputFile, this.generator.GetCode())); to explicitly specify System.Text.ASCII, which looks to be the closest match. This comes with the possibility of losing characters altogether that are printable in UTF-8 but not ASCII, but would improve handling of common special characters like ©.
  2. Use escape sequences to escape and insert any character that is more than one byte. I believe RC.exe supports some manner of escaping Unicode characters.
  3. Write the RC script in UCS-2 encoding with BOM. My understanding is that Encoding.Unicode is a superset of UCS-2 such that all 2 byte UTF-16LE characters would render correctly and only 3 byte and larger characters would have to be escaped.

Side note: Is there any reason for the strings being in Unicode to be conditional? Even if the application was compiled without Unicode support, I’d think there’d be no disadvantage to generating Unicode resources.

#if defined(_UNICODE) 
#define NBGV_VERSION_STRING(x) L ##x 
#else 
#define NBGV_VERSION_STRING(x) x 
#endif"; 

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
gundermanccommented, Mar 27, 2018

Assuming option 1 works I can probably make and contribute the fix. Should only be one line.

0reactions
heathscommented, Mar 20, 2019

The Unicode option would probably be best. RC files in the modern era are supposed to be Unicode according to the VC++ team when I recently was trying to get VSCode to diff them right (more a problem with git itself, turns out).

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

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