简体   繁体   中英

Getting NullReferenceException on Microsoft.windows.controls.MessageBox vertical scrollbar click

Getting NullReferenceException on Microsoft.windows.controls.MessageBox when i click the arrow(up or down) in the vertical scrollbar

List<string> errors = new List<string>();

errors = selectedJob.ValidationErrors;
if (errors != null && errors.Count() > 0)
{
    var msg = string.Join(Environment.NewLine,  errors);                                
    MessageBoxResult result =  Microsoft.Windows.Controls.MessageBox.Show(msg, title, System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
}

Any suggesstions would be helpful, I can't seem to figure out whats wrong here. Thanks in advance

You are creating a new empty list, but then assigning that object to selectedJob.ValidationErrors. Did you mean to use errors.AddRange(selectedJob.ValidationErrors); ?

(btw, you should use errors.Any() instead of errors.Count() > 0 )

And does using title ?? String.Empty title ?? String.Empty not throw the exception?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM