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

BUG: Passing in existing state for a field of type double is not working

Open rodzillarr opened this issue 10 years ago • 6 comments

In C# see below:

//update the initial state before calling dialog
var state = new MyDialog();

state.StringItem = someString; //this string gets copied into the called dialog
state.StringItem2 = someString2; //this string gets copied into the called dialog
state.DoubleItem = doubleVal; //this double DOES NOT get copied into the called dialog and i am prompted to enter it in the dialog

context.Call(new FormDialog<MyDialog>(state, MyDialog.BuildForm, options: FormOptions.PromptInStart), null);

neither of the following assignment substitutions work either:

state.DoubleItem = 99; //doesn't work
state.DoubleItem = 99d; //nor does this

rodzillarr avatar Apr 14 '16 20:04 rodzillarr

Actually, this is the same as the closed issue #38

I've verified that the value is known by the bot however the step is not skipped for Double values.

I've got to run somewhere but after a quick glance I believe the issue resides between lines 560 and 576 in Field.cs

        public override bool IsUnknown(T state)
        {
            var unknown = false;
            var value = GetValue(state);
            if (value == null)
            {
                unknown = true;
            }
            else
            {
                var step = _path.Last();
                var ftype = StepType(step);
                if (ftype.IsValueType && ftype.IsEnum)
                {
                    unknown = ((int)value == 0);
                }
                else if (ftype == typeof(DateTime))
                {
                    unknown = ((DateTime)value) == default(DateTime);
                }
                else if (ftype.IsIEnumerable())
                {
                    unknown = !(value as System.Collections.IEnumerable).GetEnumerator().MoveNext();
                }
            }
            return unknown;
        }

rodzillarr avatar Apr 14 '16 21:04 rodzillarr

@rodzillarr which version of Nuget are you depending on. Issue #38 should be fixed in 1.0.2 release.

msft-shahins avatar Apr 14 '16 22:04 msft-shahins

1.0.2 I believe this is a different issue. The logic to skip fields with existing state is getting called but it's not handling Doubles.

Thanks,

-r

rodzillarr avatar Apr 14 '16 23:04 rodzillarr

FYI, this is occurring because the function:

        internal static bool IsNullable(this Type type)
        {
            return (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>));
        }

in \Library\FormFlow\extensions.cs (Line 140) is returning false for System.Double so the formbuilder code isn't skipping it when it finds existing state.

-R

rodzillarr avatar Apr 15 '16 00:04 rodzillarr

This is by design. We have no idea whether or not there is a value in your field--how do we know 0.0 is no value, but 1.0 is a value? If you change your double to be a nullable field then we can distinguish and it will be skipped if you supply a value.

chrimc62 avatar Apr 15 '16 01:04 chrimc62

I figured it out right when you posted your reply and after hunting down that chunk of code. Changed my field from a double to a double? and naturally it works. Thanks!

rodzillarr avatar Apr 15 '16 01:04 rodzillarr