c# - 设置变量给我一个 NullReferenceException
问题描述
嘿,我正在做一个学校项目,当我设置一个类的变量时,它会抛出一个 NullReferenceException 你可以找到完整的项目@ https://github.com/kyllianlissens/BugManagment
if (!dataReader.IsDBNull(dataReader.GetOrdinal("user_id")))
{
task.Employee = (Employee) UserRepository.Items.Find(x => x.Id.Equals(Convert.ToInt32(dataReader["user_id"])));
}
它发生在设置 task.Employee 变量时
这是我的任务课
public class Task : Entity
{
internal Task(int id, Bug bug, string description, int size, TimeSpan timeSpent) : base(id)
{
Bug = bug;
Size = size;
TimeSpent = timeSpent;
Description = description;
Employee = null;
}
public Employee Employee { get; internal set; }
public Bug Bug { get; internal set; }
public string Description { get; internal set; }
public int Size { get; internal set; }
public TimeSpan TimeSpent { get; internal set; }
internal void AddTime(TimeSpan time)
{
TimeSpent += time;
}
}
我还尝试删除 Employee = null; 但这并没有改变任何事情。
解决方案
推荐阅读
- flutter - 为什么我无法在我的 32 位 windows 10 机器上安装颤振?
- javascript - 选择一个号码
- dax - 有更快的平均值吗?
- r - 将 xml 文件解析为具有重复下标的 R 并给出重复的行?
- javascript - 是否可以使用 nodejs 直接写入 gcp 中托管的文件
- automationanywhere - 如何在对象克隆的情况下获取 chrome 中的文本?
- wordpress - 同一页面上的多个 Vue 实例使用相同的代码库
- html - 如何使用支持所有视口的 css 将 html 表单定位在图像的特定部分?
- java - Java Mission Control 没有列出任何要连接的 JVM
- django - 使用 datetime 对象过滤 Django 中的查询集(截断为天)