Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在Microsoft.windows.controls.MessageBox垂直滚动条上获取NullReferenceException单击_C# - Fatal编程技术网

C# 在Microsoft.windows.controls.MessageBox垂直滚动条上获取NullReferenceException单击

C# 在Microsoft.windows.controls.MessageBox垂直滚动条上获取NullReferenceException单击,c#,C#,单击垂直滚动条中的箭头(向上或向下)时,在Microsoft.windows.controls.MessageBox上获取NullReferenceException List<string> errors = new List<string>(); errors = selectedJob.ValidationErrors; if (errors != null && errors.Count() > 0) { var msg = str

单击垂直滚动条中的箭头(向上或向下)时,在Microsoft.windows.controls.MessageBox上获取NullReferenceException

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);
}
List errors=newlist();
错误=selectedJob.ValidationErrors;
if(errors!=null&&errors.Count()>0)
{
var msg=string.Join(Environment.NewLine,errors);

MessageBoxResult=Microsoft.Windows.Controls.MessageBox.Show(消息、标题、System.Windows.MessageBoxButton.OK、System.Windows.MessageBoxImage.Error); }

任何建议都会有帮助,我似乎不知道这里出了什么问题。提前感谢

您正在创建一个新的空列表,但随后将该对象分配给selectedJob.ValidationErrors。 您是否打算使用
errors.AddRange(selectedJob.ValidationErrors)

(顺便说一句,您应该使用
errors.Any()
而不是
errors.Count()>0


使用
title??String.Empty
不引发异常?

在哪一行点击nullref error?这是一个非常普遍的错误,因此提供尽可能多的信息。谢谢。这是否在向上/向下错误的事件方法中?它抛出异常的代码是哪一行?您在哪里创建/初始化
title
?MessageBoxResult=Microsoft.Windows.Controls.MessageBox.Show(msg,title,System.Windows.MessageBoxButton.OK,System.Windows.MessageBoxImage.Error);}string title=string.Format(“{0}{1}”,“作业中缺少字段-”,_jobRepository.selectedJob.jobData.JobFileIO.JobName);MessageBox.show是抛出messageI-trued errors.AddRange(selectedJob.ValidationErrors)的内容,但这并没有解决问题。此外,“title”不是String.empty,它将被一些静态文本填充。有关“标题”的详细信息,请参见我的上述评论