c# - 为什么 GetAsync 方法会抛出 'System.Collection.KeyNotFoundException' ?(v4)
问题描述
我在整个对话过程中不断收到此异常:
System.Collections.Concurrent.dll 中的“System.Collections.Generic.KeyNotFoundException”
我发现这是由GetAsync
方法引起的,但我不知道为什么。如果有人能给我解释为什么抛出这个异常,以及避免它的可能方法,我将不胜感激。
我的代码:
protected override async Task OnMessageActivityAsync(
ITurnContext<IMessageActivity> turnContext,
CancellationToken cancellationToken = default(CancellationToken))
{
// ...
var uAccessor = _userState.CreateProperty<UserProfile>(nameof(UserProfile));
var userProfile = await uAccessor.GetAsync(turnContext, () =>
new UserProfile(), cancellationToken); //throws an exception
userProfile.UserInputs.Add(turnContext.Activity.Text?.Trim());
await uAccessor.SetAsync(turnContext, userProfile, cancellationToken);
// ...
}
解决方案
推荐阅读
- javascript - Canvas.clearRect 不是 React 中的函数
- r - 将列表简化为数据框并从列表中的数字向量创建新列
- python - 递归全局仅适用于某些文件夹
- vba - Powerpoint VBA循环所有幻灯片,检查标题,如果标题正确,将形状粘贴到另一个演示文稿
- android - 构建颤振应用程序时 IntelliJ 出错
- php - 问题:调用成员函数 fetch_assoc()
- module - 可以在 Raku 中导出子集吗?
- java - 弃用分页参数
- reactjs - Heroku 永远部署代码循环直到超时
- javascript - 无效的正则表达式:: 字符类中的范围乱序