Skip to content

How to Resolve Error "CS1035: End-of-file found, '*/' expected" in C#

Fix the CS1035 compiler error in C# by locating and closing unmatched multi-line comment blocks (/* without */) that cause syntax issues.

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:

  1. Single-line comments: Start with // and end automatically at the end of the line.
  2. 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.
    }
}

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?"

  1. Check Coloring: Look at syntax highlighting. Where does the code turn green (or grey)?
  2. Find /*: Search for the character sequence /*. Ensure every instance has a matching */.
  3. Check Strings: /* inside a string "/*" is fine. /* in code is a comment start.
Navigation