Inside ContinueDialogAsync I am trying to access the dialog's context object outerDc which contains my bot's state data, as I configured and see in the immediate/watch window.outerDc.Context.TurnState Count = 3 [0]: {[BotIdentity, System.Security.Claims.ClaimsIdentity]} [1]: {[Microsoft.Bot.Connector.IConnectorClient, Microsoft.Bot.Connector.ConnectorClient]} [2]: {[ConversationState, Microsoft.Bot.Builder.BotState+CachedBotState]} outerDc.Context.TurnState["ConversationState"] {Microsoft.Bot.Builder.BotState.CachedBotState} Hash: "{}" State: Count = 2这里是QuickWatch表达式,突出显示的值正是我所需要的.Here is the QuickWatch expression and the highlighted value is exactly what I need. 当我尝试在我的代码中使用表达式((Microsoft.Bot.Builder.BotState.CachedBotState)outerDc.Context.TurnState ["ConversationState"]).State 时,似乎是 CachedBotState 不属于名称空间/程序包.同样, Microsoft.Bot.Builder.BotState.CachedBotState 是 Microsoft.Bot.Builder.Core nuget程序包的一部分,该程序包仍处于预览阶段.When I try to use the expression ((Microsoft.Bot.Builder.BotState.CachedBotState)outerDc.Context.TurnState["ConversationState"]).State in my code, it seems CachedBotState is not part of the namespace/package. Also it seems that Microsoft.Bot.Builder.BotState.CachedBotState is part of the Microsoft.Bot.Builder.Core nuget package which is still in preview stage.我知道我可以将 TurnState 对象作为附加参数从 OnTurnAsync 传递到我的对话框.但是,当对话框显示它已经存在时,我想通过该对话框的上下文进行访问.有办法吗?I know I can pass the TurnState object as an additional parameter from the OnTurnAsync to my dialog. But, I want to access it through the dialog's context, when it shows it is already there. Is there a way to do that?请让我知道是否可以详细说明.Please let me know if I can elaborate more.推荐答案首先, CachedBotState 是内部实现细节,而不是您期望使用的东西.同样,您真的不应该深入研究 TurnState 并期望使用其中不受您控制的值,因为这也只是有关bot状态如何维护作用域值的实现细节.转弯.我建议您放弃这种方法,因为最终,整个实现可能会在下一个版本中更改(因为它是内部详细信息,并且不受存储规则的约束),然后您的代码将因此中断.First, CachedBotState is an internal implementation detail and not something you should ever be expecting to use. Likewise you really shouldn't be digging into the TurnState and expecting to work with values inside of there which are not under your control as it's also just an implementation detail of how the bot state maintains values for the scope of the turn. I would recommend you abandon this approach because, ultimately, the whole implementation could change in the next version (since it's internal details and not subject to semver rules) and then your code would break as a result.相反,您应该做的是在创建它时将 IStatePropertyAccessor< TurnState> 传递给 SomeDialog 的构造函数,并将其添加到 DialogSet .这使 SomeDialog 能够读取/写入给定回合的特定属性,并且您的代码将改为如下所示:Instead, what you should be doing is passing your IStatePropertyAccessor<TurnState> through to the constructor of the SomeDialog as you're creating it and adding it to the DialogSet. This gives SomeDialog the ability to read/write that particular property for a given turn and your code would change to look like this instead:public override Task<DialogTurnResult> ContinueDialogAsync(DialogContext outerDc, CancellationToken cancellationToken = default(CancellationToken)){ // Access state via the property accessor rather than trying to access raw internals of bot state management var turnState = await _turnStatePropertyAccessor.GetAsync(outerDc.Context); outerDc.EndDialogAsync(); return base.ContinueDialogAsync(outerDc, cancellationToken);} 这篇关于从DialogContext获取TurnState数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-15 19:10