# An error occurred while parsing EntityName

Source: https://xmlvalid.com/errors/error-occurred-while-parsing-entityname

> A bare ampersand (&amp;) in text or in an attribute.

The message, as .NET reports it: `An error occurred while parsing EntityName. Line 1, position 17.`

## Why it happens

- An unescaped `&`: a company name, a URL query string.
- XML built with string concatenation or interpolation instead of an XML API.

## How to fix it

- Write `&amp;` for every literal ampersand. `XmlWriter`, `XElement` and `XmlSerializer` escape it for you; `SecurityElement.Escape` does it for a string.
- .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 [xmlParseEntityRef: no name](https://xmlvalid.com/errors/xmlparseentityref-no-name): `xmlParseEntityRef: no name`

## Example that fails

```xml
<company>Smith & Sons</company>
```

## Fixed

```xml
<company>Smith &amp; Sons</company>
```
