Reputation: 181
Using bot simulator :
Have this code in MessagesController :
await Conversation.SendAsync(activity, () => new RootLuisDialog());
In 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);
}
This makes an Exception :
{"Type 'Microsoft.Bot.Connector.Activity' in Assembly 'Microsoft.Bot.Connector, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is not marked as serializable."} Data: {System.Collections.ListDictionaryInternal} HResult: -2146233076 HelpLink: null InnerException: null Message: "Type 'Microsoft.Bot.Connector.Activity' in Assembly 'Microsoft.Bot.Connector, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is not marked as serializable." Source: "mscorlib" StackTrace: " at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type)\r\n at System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context)\r\n at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo()\r\n at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, 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(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)\r\n at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)\r\n at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream 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 item)\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--- 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.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--- 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.ScoringDialogTask1.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__6
1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.Co mpilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\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--- 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.Conversation.d__4.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.Throw ForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Conversation.d__2.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 System.Runtime.CompilerServices.TaskAwaiter.GetResult()\r\n at MessengerBot.MessagesController.d__1.MoveNext() in C:\myapp\MessagesController.cs:line 60" TargetSite: {System.Reflection.MemberInfo[] InternalGetSerializableMembers(System.RuntimeType)}
I am not pretty sure that i understand what exception here is ... some help ?
Edit : I solved the problem with new constructor for rootluisdialog with parameter - activity.
await Conversation.SendAsync(activity, () => new RootLuisDialog(activity)); and then in the RootLuisDialog i have this :
Activity activity;
public RootLuisDialog(Activity activity)
{
this.activity = activity;
}
Upvotes: 1
Views: 794
Reputation: 26976
The Activity
class isn't serialisable, which is the error you're seeing. All public or protected properties in the LuisDialog
need to be serialisable so that they can be stored as contexts between responses.
Assuming your Dialog class is inheriting from LuisDialog
then this should already be taking care of grabbing the activity from the intent - in general you'd be working with the context and the result from LUIS rather than the activity directly (as you would if you were creating a straight up IDialog
implementation).
Passing it in from the controller also won't do what you expect as it won't be included on subsequent calls in the conversation.
Upvotes: 2