# Unexpected end of file while parsing Comment has occurred

Source: https://xmlvalid.com/errors/unexpected-end-of-file-while-parsing-comment

> A comment is never closed, so it runs to the end of the document.

The message, as .NET reports it: `Unexpected end of file while parsing Comment has occurred. Line 2, position 1.`

## Why it happens

- A `\<!--` without its `-->`, or a comment closed with `->` or `--!>`.

## How to fix it

- Close the comment with `-->`. The same message with *CDATA* instead of *Comment* means an unclosed CDATA section (`]]>` is missing).
- .NET throws an `XmlSchemaValidationException` at the first schema error unless `XmlReaderSettings.ValidationEventHandler` is set, which then receives every one with its line and position. A well-formedness error is an `XmlException` and ends reading whatever the settings.

## The same problem in xmlvalid

libxml2, which xmlvalid validates with, reports it as [Comment not terminated](https://xmlvalid.com/errors/comment-not-terminated): `Comment not terminated`

## Example that fails

```xml
<note><!-- todo </note>
```

## Fixed

```xml
<note><!-- todo --></note>
```
