ValidationResult throws : "Object reference not set to an instance of an object". when passing back choices
Stack Trace:
Exception: Exception caught: 'Microsoft.Bot.Builder.FormFlow.FormCanceledException1' in mscorlib.dll ("Object reference not set to an instance of an object."). Exception caught: 'Microsoft.Bot.Builder.FormFlow.FormCanceledException1' in mscorlib.dll ("Object reference not set to an instance of an object.")
Hi, I am trying to generate form flow and during validation, If user enters wrong text then i am passing choices to select from but bot however throws above exception and emulator hangs.
Below is the example
.Field(nameof(RegistrationForm.ModelNumber), validate: async (state, value) =>
{
var modelsSuggestion = PimsServiceClient.GetModelSuggestion();
ValidateResult validateResult = new ValidateResult()
{
IsValid = modelsSuggestion.Any(m => m.ToLower().Equals(value?.ToString().ToLower())),
Value = value,
Choices = new List
/* Do some database stuff */
return validateResult;
})
Is it possible modelsSuggestion contains a null value? If you break when the exception is thrown you an see where the null is coming from.
Hi @chrimc62
I will check again tonight and will come back with information if possible.
Cheers
Hi @chrimc62
I tried again and fugred out that i had to provide all the property values for choices like below
var choices = new List<Choice>();
choices.Add(new Choice { Description = new DescribeAttribute("Tes1", null, "Tes1", null, null), Value ="Tes1", Terms = new TermsAttribute("Tes1", "T1")});
choices.Add(new Choice { Description = new DescribeAttribute("Test2", null, "Test2", null, null), Value = "Test2", Terms = new TermsAttribute("Test2", "T2") });
ValidateResult validateResult = new ValidateResult()
{
/*if modelSuggestion != null && modelsSuggestion.Any()*/
IsValid = false,
Value = value,
Choices = choices
};