roslyn: #if preprocessor directive incorrectly handles enclosed C# verbatim string

To reproduce, just use this code and make sure that DEBUG is set:

#if !DEBUG
    [Description(@"
    # text")]
    class Test
    {
    }
#endif

Actually, this produces a CS1024 error because the compiler seems to interpret the “# text” portion of the string as a preprocessor directive.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 27 (25 by maintainers)

Most upvoted comments

Sorry, busy days here lately 😃 It’s definitely the latter - surrounding a chunk of code with #if <directive>/#endif for example should just work. Most developers won’t understand why this broke without digging a little.

This gets further complicated in our case because we do compile-time replacement of strings for localization. That wasn’t the case hit here (it was simple markdown), but the fact that a string our translators give us can just break builds one day is a little scary. I simply think we can do better here.