I was building a bot where I wanted to save and retrieve some state in the Bot State Service (using .NET Bot Builder SDK). As saving in PrivateConversationData or UserData properties of IDialogContext wasn't working (it wasn't saving anything), what I did was to write a piece of code similar to the following inside a dialog:
List<Value> valuesToStore = GetSomeValuesToStore();
StateClient stateClient = ((Activity)context.Activity).GetStateClient();
BotData userData = await stateClient.BotState.GetUserDataAsync(context.Activity.ChannelId, context.Activity.Conversation.Id);
if (userData != null && userData.GetProperty<List<Value>>(VALUES_NAME) != null)
{
DoSomethingWithUserData(userData);
}
else
{
//save values in state
userData.SetProperty(VALUES_NAME, valuesToStore);
await stateClient.BotState.SetUserDataAsync(context.Activity.ChannelId, context.Activity.Conversation.Id, userData);
}
And after that code being executed only once, I started getting the following Exception whenever a new message arrived to my bot:
"Settings must be of the form \"name=value"\."
Which it seemed to be something related to Azure Storage connection (what Bot Framework uses to store state I guess). Somehow I got the bot in an inconsistent state, the only solution I found for this was creating a new bot in Bot Framework Developer Portal, and saving state on my own.
And some time ago, a similar I got a similar error:
"Null properties cannot be encrypted. Please assign a default value to the property if you wish to encrypt it.";
Which obviously was because the objects I was trying to store contained properties with null values. But same thing, I couldn't make the bot return to the normal state; I had to create a new one because every new message resulted into an exception whenever the bot tried to retrieve the state.
Any thoughts on this?
Thanks!