none
Basic c# failing to compile and reporting incorrect error: known issue/bug? RRS feed

  • Question

  • The following extremely simple bit of code demonstrates what must be a bug/defect in VS.  Two identical (except for variable names) string assignments; one is fine, the other shows errors such as "CS0201 Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement," "CS1525 Invalid expression term ''," and "CS1002 ; expected."

    Screenshot attached.

    Is this a known issue?

    It's not blocking because a separate line can be created and (somehow?) works, but it seems like a pretty severe issue that could cause a lot of frustration to new developers trying to learn the language and tool.

    Screen shot of Visual Studio showing errors

    Sunday, October 20, 2019 4:46 PM

Answers

  • Ok, I have managed to reproduce the issue:

    Screenshot

    I did it by using charmap.exe to select a nonprintable character (U+034F - Combining Grapheme Joiner) and pasting it into the source code. The code appears "normal" at first sight, but produces compilation errors similar to the ones that you mentioned.

    It can be fixed by typing a "real" space on top of the "bad" character.

    • Marked as answer by RyanRogers() Monday, October 21, 2019 8:32 PM
    Sunday, October 20, 2019 8:15 PM
    Moderator
  • One remote possibility is that there is a masquerading character. There might be a character that looks like a space that is not, or something like that.


    Sam Hobbs
    SimpleSamples.Info

    Sunday, October 20, 2019 7:45 PM

All replies

  • Hello,

    I've never seen this and can not duplicate. What version of Visual Studio is being used? Have you tried restarting Visual Studio and doing a project rebuild?


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Sunday, October 20, 2019 5:50 PM
    Moderator
  • One remote possibility is that there is a masquerading character. There might be a character that looks like a space that is not, or something like that.


    Sam Hobbs
    SimpleSamples.Info

    Sunday, October 20, 2019 7:45 PM
  • If you know how to use the binary editor in VS then you can look for strange characters that way. It would be helpful to know exactly what the cause was if it is anything like that.


    Sam Hobbs
    SimpleSamples.Info

    Sunday, October 20, 2019 8:12 PM
  • Ok, I have managed to reproduce the issue:

    Screenshot

    I did it by using charmap.exe to select a nonprintable character (U+034F - Combining Grapheme Joiner) and pasting it into the source code. The code appears "normal" at first sight, but produces compilation errors similar to the ones that you mentioned.

    It can be fixed by typing a "real" space on top of the "bad" character.

    • Marked as answer by RyanRogers() Monday, October 21, 2019 8:32 PM
    Sunday, October 20, 2019 8:15 PM
    Moderator
  • great work! i'm guessing a character was somehow copied strangely from onenote or similar.  i'd suggest that the vs UI should be aware enough to detect this, but it's likely uncommon enough that it's not terribly necessary.

    thanks for solving the mystery, in any event!

    Monday, October 21, 2019 8:34 PM
  • Note that I was the one that suggested there might be a character that looks like a space that is not, or something like that.



    Sam Hobbs
    SimpleSamples.Info

    Monday, October 21, 2019 10:17 PM