使用僵尸模拟器:
在MessagesController中使用此代码:
await Conversation.SendAsync(activity, () => new RootLuisDialog());
在RootLuisDialog中:
[LuisIntent("")]
[LuisIntent("None")]
public async Task None(IDialogContext context, LuisResult result)
{
string message = $"Sorry, I did not understand '{result.Query}'. Type 'help' if you need assistance.";
await context.PostAsync(message);
context.Wait(this.MessageReceived);
}
这是一个例外:
{“在汇编中键入'Microsoft.Bot.Connector.Activity' 'Microsoft.Bot.Connector,Version = 3.0.0.0,Culture = neutral, PublicKeyToken = 31bf3856ad364e35'未标记为可序列化。“} 数据:{System.Collections.ListDictionaryInternal} HResult:-2146233076 HelpLink:null InnerException:null 消息:“在程序集'Microsoft.Bot.Connector中键入'Microsoft.Bot.Connector.Activity',版本= 3.0.0.0,Culture = neutral, PublicKeyToken = 31bf3856ad364e35'未标记为可序列化。“ 资料来源:“mscorlib” StackTrace:“在System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType) 输入)\ r \ n at System.Runtime.Serialization.FormatterServices.GetSerializableMembers(类型 type,StreamingContext context)\ r \ n at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo(个)\ r \ n 在 System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(对象 obj,ISurrogateSelector surrogateSelector,StreamingContext context, SerObjectInfoInit serObjectInfoInit,IFormatterConverter转换器, ObjectWriter objectWriter,SerializationBinder binder)\ r \ n at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo,NameInfo memberNameInfo,NameInfo typeNameInfo)\ r \ n at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(对象 graph,Header [] inHeaders,__BinaryWriter serWriter,Boolean fCheck)\ r \ n at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(流 serializationStream,Object graph,Header [] headers,Boolean fCheck)\ r \ n at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(流 serializationStream,Object graph)\ r \ n at Microsoft.Bot.Builder.Internals.Fibers.FormatterStore
1.Microsoft.Bot.Builder.Internals.Fibers.IStore<T>.Save(T item)\r\n at Microsoft.Bot.Builder.Internals.Fibers.ErrorResilientStore
1.Microsoft.Bot.Builder.Internals.Fibers.IStore.Save(T 项目)\ r \ n at Microsoft.Bot.Builder.Internals.Fibers.FactoryStore1.Microsoft.Bot.Builder.Internals.Fibers.IStore<T>.Save(T item)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__21
1.MoveNext(个)\ r \ n --- 从抛出异常的先前位置开始的堆栈跟踪结束 --- \ r \ n在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)\ r \ n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)\ r \ n在Microsoft.Bot.Builder.Dialogs.Internals.ReactiveDial ogTask。 d__51.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.LocalizedDialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__2
1.MoveNext(个)\ r \ n --- 从抛出异常的先前位置开始的堆栈跟踪结束 --- \ r \ n在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)\ r \ n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)\ r \ n at Microsoft.Bot.Builder.Dialogs.Internals.ScoringDialogTask1.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__6
1.MoveNext(个)\ r \ n --- 从抛出异常的先前位置开始的堆栈跟踪结束 --- \ r \ n在System.Runtime.Co mpilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)\ r \ n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)\ r \ n at Microsoft.Bot.Builder.Dialogs.Internals.PersistentDialogTask.d__61.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at Microsoft.Bot.Builder.Dialogs.Internals.PersistentDialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__6
1.MoveNext(个)\ r \ n --- 从抛出异常的先前位置开始的堆栈跟踪结束 --- \ r \ n在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)\ r \ n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)\ r \ n at Microsoft.Bot.Builder.Dialogs.Conversation.d__4.MoveNext(个)\ r \ n --- 从抛出异常的先前位置开始的堆栈跟踪结束 --- \ r \ n在System.Runtime.CompilerServices.TaskAwaiter.Throw ForNonSuccess(任务任务)\ r \ n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)\ r \ n at Microsoft.Bot.Builder.Dialogs.Conversation.d__2.MoveNext(个)\ r \ n --- 从抛出异常的先前位置开始的堆栈跟踪结束 --- \ r \ n在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)\ r \ n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)\ r \ n at System.Runtime.CompilerServices.TaskAwaiter.GetResult()\ r \ n at MessengerBot.MessagesController.d__1.MoveNext()in C:\ myapp \ MessagesController.cs:第60行“ TargetSite:{System.Reflection.MemberInfo [] InternalGetSerializableMembers(System.RuntimeType)}
我不太确定我明白这是什么例外...... 一些帮助?
编辑:我使用参数 - activity的rootluisdialog的新构造函数解决了这个问题。
await Conversation.SendAsync(activity,()=&gt; new RootLuisDialog(activity)); 然后在RootLuisDialog中我有这个:
Activity activity;
public RootLuisDialog(Activity activity)
{
this.activity = activity;
}
答案 0 :(得分:1)
Activity
课程不可串行化,这是您所看到的错误。 LuisDialog
中的所有公共或受保护属性都需要是可序列化的,以便它们可以存储为响应之间的上下文。
假设您的Dialog类继承自LuisDialog
,那么这应该已经在处理从意图中获取活动 - 通常您将使用来自LUIS的上下文和结果而不是直接活动(就像你创建一个直接IDialog
实现一样)。
从控制器传递它也不会做你期望的事情,因为它不会被包含在对话的后续呼叫中。