How to view EntityValidationErrors in Visual Studio

Back to blog

If Entity Framework throws a validation exception when saving, Visual Studio reports the message,

Validation failed for one or more entities. See ‘EntityValidationErrors’ property for more details.

But the in-built ‘View Detail’ dialog doesn’t let you drill into the EntityValidationErrors property.

To view the EntityValidationErrors collection, add the following Watch expression to the Watch window.

Which displays a similar to,

The watch expression ‘$exception’ displays any exception thrown in the current context, even if it has not been caught and assigned to a variable.