Crash adding a new record from DataGrid


BookApplication, press Add to add a new book, click on Title to start editing cell, then lose focus clicking on another control (for example, "Address Book" tab) and there is an exception from line

_Title = StructuralObject.SetValidValue(value, false);

because it tries to set a null value to the Title.

How can this be avoided?


jbe2277 wrote Mar 23, 2013 at 11:00 AM

Thank you for your feedback.

I’m able to see this exception in the Debugger but the BookLibrary application doesn’t crash. The exception is catched by the WPF Binding infrastructure. Therefore, this shouldn’t be an issue.

The exception comes because the Title column in the database is set to Nullable = false. When the WPF Binding tries to write “null” into the property setter then this exception is thrown. You might initialize the Title and Author properties with “string.Empty” in the constructor of the Book class.

This exception does not occur anymore in the new WAF BookLibrary sample application because now it uses the POCO approach.

gusi wrote Mar 23, 2013 at 11:26 AM

Hi! And thanks for checking this.
You're right, I had the debugger set to halt on exceptions, but without the debugger the exception is correctly handled. Sorry for not seeing this first! :(

wrote Jun 18, 2013 at 9:13 AM

wrote Aug 25, 2013 at 1:10 PM