botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

ValidationResult throws : "Object reference not set to an instance of an object". when passing back choices

Open murtazadhari opened this issue 10 years ago • 3 comments

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(modelsSuggestion.Select(s => new Choice { Value = s } })) };

                    /* Do some database stuff */
                    return validateResult;
                })

murtazadhari avatar Sep 22 '16 13:09 murtazadhari

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.

chrimc62 avatar Oct 05 '16 03:10 chrimc62

Hi @chrimc62

I will check again tonight and will come back with information if possible.

Cheers

murtazadhari avatar Oct 06 '16 04:10 murtazadhari

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
                };

murtazadhari avatar Oct 06 '16 12:10 murtazadhari