Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

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

I'm getting this unexpected character '' error and I don't understand why.

var list = new List<MyModel>();    
list.Add(new MyModel() {
    variable1 = 942,
    variable2 = 2001,
    variable3 = "my text",
    variable4   = 123
​}); // CS1056 Unexpected character ''  on this line
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

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)

over 4 years ago · Santiago Trujillo Report

0

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

over 4 years ago · Santiago Trujillo Report

0

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.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!