When I try it in my app built for release I do get a runtime error: "Nullable object must have a value."
Person p = new Person();
Console.WriteLine(p.Valid);
So I would suspect you have a try - catch somewhere which is picking up on it.
Check your settings for debug:
"Debug" menu..."Exceptions..."
In the dialog, check the "thrown" and "user-unhandled" columns and see if there is anything you can do to get the same results as the release version.
[Update]
Sorry for the delay...I was thinking! (And that takes me some time...)
I can duplicate your problem and get an exception in VS but not when "live" very simply, without using a BindingSource, just by moving the Valid getter access to a different thread:
{
BackgroundWorker work = new BackgroundWorker();
work.DoWork += work_DoWork
work.RunWorkerAsync();
}
void work_DoWork(object sender, DoWorkEventArgs e)
{
Person p = new Person();
Console.WriteLine(p.Valid);
}
Which implies that the bound event is being executed on a different thread, which "swallows" the exception for some reason.
So... What I suspect is happening: the DataBinding is executing the code on a different thread, and when the exception is unhandled, the system shuts down the thread and doesn't notify you outside of the debugger.
A quick test:
BackgroundWorker work = new BackgroundWorker();
work.DoWork += work_DoWork;
work.RunWorkerAsync();
...
void work_DoWork(object sender, DoWorkEventArgs e)
{
try
{
Person p = new Person();
Console.WriteLine(p.Valid);
}
catch (Exception ex)
{
File.WriteAllText(@"D:\Temp\aaaaa.txt", DateTime.Now.ToString() + " " + ex.Message);
}
}
And the exception is logged each end every time.
What do you do about it? Good question: I'd suggest a try-catch but exactly where you put it, I don't know...