How to view 'Entity Framework DbEntityValidation Exception was unhandled by user code' errors?

By · July 23, 2014 · 1 comment

Entity Framework DbEntityValidation Exception was unhandled by user code

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


If you are using Entity Framework and have received this error message and have been frustrated by not being able to see what the actual problem is in Visual Studio then there is a simple solution.

Simply add the following expression to your Watch window:

((System.Data.Entity.Validation.DbEntityValidationException)$exception).EntityValidationErrors

This will give you the information you need to diagnose the problem.

Here's an example of what you will see:

DbEntityValidation Exception watch

Alternately you can press Ctrl+F9 to bring up the QuickWatch dialog and enter the same expression there.

Get the latest posts delivered to your inbox.

Comments (1)

# Posted by Ben Hudelson · March 15, 2016

Thanks. Saved me some time.

Reply

Ben Hudelson
Leave a Comment

All comments are moderated and rel="nofollow" is in use. Avatars are sourced from gravatar.com – a globally recognised avatar.

Type the numbers from the picture above

About me
John Avis ...mostly about web development and programming, with a little bit of anything else related to the Internet, computers and technology.

profile for John at Stack Overflow, Q&A for professional and enthusiast programmers
Subscribe

Get the latest posts delivered to your inbox. *