Why do I get an CS1056 Unexpected character '' on this code

I just deleted the file Version=v4.0.AssemblyAttributes.cs(1,1,1,1) located in my temp folder C:\Users\MyUser\AppData\Local\Temp and then it works perfectly.

For .NET Core you have to delete .NETCoreApp,Version=v2.1.AssemblyAttributes.cs

File to delete


As mentioned by Daneau in the accepted answer, the problem is by a character that is not visible in the IDE.

Here are several solutions to find the invisible character with Notepad++.

Solutions 1: Show Symbol

  • Copy the code to Notepad++,
  • Select View -> Show Symbol -> Show All Characters

This can show invisible control characters.

Solutions 2: Convert to ANSI

  • Copy the code to Notepad++,
  • Select Encoding- > Convert to ANSI

This will convert the invisible character to ? if it is a none ANSI character.

Solutions 3: Remove none ASCII characters

  • Copy the code to Notepad++,
  • Open the Find window (Ctrl+F)
  • Select the Replace tab
  • in "Find what" write: [^\x00-\x7F]
  • Leave "Replace with" empty
  • In "Search Mode" select "Regular expression"
  • Find and remove the none ASCII characters

This will remove none ASCII characters.

Note: This can remove valid non ASCII characters (in strings and comments) so try to skip those if you have any.

Tip: Use HEX-Editor plugin

Use Notepad++ HEX-Editor plugin to see the binary code of text. Any character out of the range of 0x00 - 0x7F (0 - 127) is a non ASCII character and a suspect of being the problem.


From what the error says and the actual error code I got from an Online compiler after copy/pasting, Your code on this line contains a character that is not visible but that the compiler is trying to interpret. Simply try erase every character starting at your closing bracket towards your number 3 and press Enter again It should be working (it did work for me)


Just reporting my direct experience. As Daneau wrote, I had a character (ASCII DLE, I copied while messing up a zebra printer) hiding in the text. I could not afford to rewrite everything, so I used notepad++ "View->Show Symbol->Show All Characters" feature. I apologize for not commenting Daneau entry, but I don't have enough reputation.

Tags:

C#