How to Resolve Error "CS1035: End-of-file found, '*/' expected" in C#
The Compiler Error CS1035 is a syntax error regarding Comments. The message reads: "End-of-file found, '/' expected"*.
In C#, there are two types of comments:
- Single-line comments: Start with
//and end automatically at the end of the line. - Multi-line comments: Start with
/*and must be explicitly closed with*/.
This error occurs when you open a multi-line comment block but forget to close it. The compiler treats everything following the initial /*—including valid code, curly braces, and namespaces—as part of the comment. When it reaches the physical end of the file without finding the closing */, it reports this error.
This guide explains how to identify and close runaway comments.
Understanding Comment Blocks
The C# compiler ignores everything between /* and */.
- Valid:
/* This is a comment */ - Valid:
/*
This spans
multiple lines
*/ - Invalid:
/* This comment never ends...(Triggers CS1035)
Because the compiler ignores the rest of the file, this error often triggers a cascade of other errors (like "Type expected" or "Namespace missing") because the closing braces } of your classes were "commented out."
Scenario 1: Forgotten Closing Tag
This is the most common cause. You started a comment block to temporarily disable a chunk of code or write documentation, but missed the closing tag.
Example of error
using System;
public class Program
{
static void Main()
{
Console.WriteLine("Hello");
/* We plan to refactor this later...
int x = 10;
int y = 20;
// The file ends here.
// The compiler is still looking for */
}
}
Build Output:
error CS1035: End-of-file found, '*/' expected
Solution: Close the Comment
Locate where the comment logic should end and add */.
public class Program
{
static void Main()
{
Console.WriteLine("Hello");
/* We plan to refactor this later...
int x = 10;
int y = 20;
*/ // ✅ Correct: Comment block closed.
}
}
Visual Studio Tip:
If you look at your code in an IDE (like Visual Studio or VS Code), comments are usually colored differently (e.g., Green). If all your code at the bottom of the file has turned green, scroll up until you find the start of the green block. That is your unclosed /*.
Scenario 2: Accidental Opening Tag
Sometimes, a typo creates a comment opener where none was intended. This is common when typing directory paths, division operations, or regex patterns.
Example of error
Accidentally typing /* instead of just / or *.
public void Calculate()
{
int a = 100;
int b = 5;
// ⛔️ Error CS1035: The sequence '/*' starts a comment.
// The intended math was 'a / *pointer' or just a typo for 'a / b'.
// Ideally this specific typo is rare, but consider strings:
string pattern = "/*"; // This is valid inside a string.
// But this outside a string is fatal:
int result = a /* b;
}
Solution: Check Syntax
Ensure you aren't combining the division operator / with the multiplication operator * without spacing, or typing path separators incorrectly.
public void Calculate()
{
int a = 100;
int b = 5;
// ✅ Correct: Spacing clarifies intent (though logic might still be odd)
int result = a / b;
}
Conclusion
CS1035 is the compiler asking: "Where does the comment end?"
- Check Coloring: Look at syntax highlighting. Where does the code turn green (or grey)?
- Find
/*: Search for the character sequence/*. Ensure every instance has a matching*/. - Check Strings:
/*inside a string"/*"is fine./*in code is a comment start.