c# - 如何在调试时找到我丢失的值?
问题描述
我尝试使用以下代码向我的 dbcontext 异步添加一些内容:
var entry = await _context.AddAsync(person);
但是,我得到以下异常:
System.ArgumentNullException:值不能为空。参数名称:key
在 System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument 参数)
在 System.Collections.Generic.Dictionary`2.FindEntry(TKey 键)
在 System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value)
在 Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.TryGetEntry(对象实体,IEntityType entityType)
在 Microsoft.EntityFrameworkCore.ChangeTracking.Internal.NavigationFixer.InitialFixup(InternalEntityEntry 条目,ISet`1 处理的ForeignKeys,布尔 fromQuery)
在 Microsoft.EntityFrameworkCore.ChangeTracking.Internal.NavigationFixer.StateChanged(InternalEntityEntry 条目,EntityState oldState,布尔 fromQuery)
在 Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntryNotifier.StateChanged(InternalEntityEntry 条目,EntityState oldState,布尔 fromQuery)
在 Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.FireStateChanged(EntityState oldState)
在 Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.d__18.MoveNext()
--- 从先前抛出异常的位置结束堆栈跟踪 ---
在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)
在 Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityGraphAttacher.d__6.MoveNext()
--- 从先前抛出异常的位置结束堆栈跟踪 ---
在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)
在 Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityEntryGraphIterator.d__1`1.MoveNext()
--- 从先前抛出异常的位置结束堆栈跟踪 ---
在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)
在 Microsoft.EntityFrameworkCore.DbContext.d__64.MoveNext()
--- 从先前抛出异常的位置结束堆栈跟踪 ---
在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)
在 Microsoft.EntityFrameworkCore.DbContext.d__66`1.MoveNext()
--- 从先前抛出异常的位置结束堆栈跟踪 ---
在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)
在 System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
在 PersonRepository.d__4.MoveNext()
--- 从先前抛出异常的位置结束堆栈跟踪 ---
在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)
在 System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
在 PersonController.cs:line 63 中的 PersonController.d__3.MoveNext()
在阅读这些陈述时,我找不到我可能遗漏的值。在调试时我不知道要寻找什么。如何在调试时找到我丢失的值?
解决方案
看起来为您要添加的人定义的 ID 为空。如果您没有配置数据库 ID 生成,则需要在将其添加到上下文之前为该人员提供一个 ID。
推荐阅读
- raku - Raku mixin 如何与运算符重载一起工作?
- python - 如果变量没有,我们可以使用变量调用方法吗?
- r - 使用 JuliaCall 将 NA 从 R 传递给 Julia 函数
- ckeditor - ckeditor 在 text 前后添加 text 类型的 unwantdd 标签
- string - 输入'列表
' 不是子类型 'List - php - 如何检查子数组中的值?
- javascript - 如何在不创建循环的情况下使 clearInterval 停止?
- javascript - 为我的 API 应用程序获取 Auth0 用户管理 API 令牌
- spring-boot - Spring Cloud Gateway,如何更改超出请求限制的错误状态类型?
- javascript - 每周数据未在 amCharts 烛台图表中正确显示