代码之家  ›  专栏  ›  技术社区  ›  Friso

如何查找调试时丢失的值?

  •  1
  • Friso  · 技术社区  · 6 年前

    我尝试使用以下代码异步地向dbcontext添加一些内容:

    var entry = await _context.AddAsync(person);

    但是,我得到了以下异常:

    System.ArgumentNullException:值不能为空。参数名称:key

    在system.throwhelper.throwargumentnullexception(exceptionargument参数)

    在system.collections.generic.dictionary`2.findentry(tkey key键)

    at system.collections.generic.dictionary`2.tryGetValue(tKey键,tValue&值)

    在Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.TryGetEntry(对象实体,IEntityType EntityType)

    位于Microsoft.EntityFrameworkCore.ChangeTracking.Internal.NavigationFixer.InitialFixUp(InternalEntityEntry条目,ISET`1 handledForeignKeys,Boolean FromQuery)

    在Microsoft.EntityFrameworkCore.ChangeTracking.Internal.NavigationFixer.StateChanged上(InternalEntityEntry条目、EntityState OldState、Boolean FromQuery)

    位于Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntryNotifier.StateChanged(InternalEntityEntry条目,EntityState OldState,Boolean FromQuery)

    在Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.FireStateChanged(EntityState OldState)

    在Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.d_u 18.MoveNext()

    ---从引发异常的上一个位置的堆栈结束跟踪---

    在system.runtime.exceptionservices.exceptiondispatchinfo.throw()

    在system.runtime.compilerservices.taskawaiter.handlenonSuccessandDebuggerNotification(任务任务)

    在Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityGraphAttacher.d_u 6.MoveNext()

    ---从引发异常的上一个位置的堆栈结束跟踪---

    在system.runtime.exceptionservices.exceptiondispatchinfo.throw()

    在system.runtime.compilerservices.taskawaiter.handlenonSuccessandDebuggerNotification(任务任务)

    在Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityEntryGraphiterator.d_u 1`1.MoveNext()

    ---从引发异常的上一个位置的堆栈结束跟踪---

    在system.runtime.exceptionservices.exceptiondispatchinfo.throw()

    在system.runtime.compilerservices.taskawaiter.handlenonSuccessandDebuggerNotification(任务任务)

    在Microsoft.EntityFrameworkCore.dbContext.d_u 64.MoveNext()

    ---从引发异常的上一个位置的堆栈结束跟踪---

    在system.runtime.exceptionservices.exceptiondispatchinfo.throw()

    在system.runtime.compilerservices.taskawaiter.handlenonSuccessandDebuggerNotification(任务任务)

    在Microsoft.EntityFrameworkCore.dbContext.d_u 66`1.MoveNext()

    ---从引发异常的上一个位置的堆栈结束跟踪---

    在system.runtime.exceptionservices.exceptiondispatchinfo.throw()

    在system.runtime.compilerservices.taskawaiter.handlenonSuccessandDebuggerNotification(任务任务)

    在system.runtime.compilerservices.taskawaiter`1.getresult()

    在personrepository.d_u4.moveNext()

    ---从引发异常的上一个位置的堆栈结束跟踪---

    在system.runtime.exceptionservices.exceptiondispatchinfo.throw()

    在system.runtime.compilerservices.taskawaiter.handlenonSuccessandDebuggerNotification(任务任务)

    在system.runtime.compilerservices.taskawaiter`1.getresult()

    在personcontroller.cs中的personcontroller.d_uu 3.moveNext()处:第63行

    在阅读这些语句时,我找不到可能丢失的值。在调试的时候我不知道该找什么。 如何查找调试时丢失的值?

    1 回复  |  直到 6 年前
        1
  •  1
  •   keithwill    6 年前

    似乎为您要添加的人定义的ID为空。如果没有配置数据库ID生成,则在将其添加到上下文之前,需要为此人提供一个ID。

    推荐文章