Botbuilder-dotnet: Creating custom dialog inherits from InputDialog crashed in Bot Framework composer

Created on 18 Dec 2020  路  8Comments  路  Source: microsoft/botbuilder-dotnet

Version

Bot Framework composer 1.3.0

Describe the bug

Application get crashed.

To Reproduce

created custom action class using InputDialog and created schema file. Try to use this custom class in bot composer, while running the application & get crashed.

Log information

at Microsoft.Bot.Builder.Dialogs.Adaptive.Input.InputDialog.d__57.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at Microsoft.Bot.Builder.Dialogs.Adaptive.Input.InputDialog.<PromptUserAsync>d__59.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult()
at Microsoft.Bot.Builder.Dialogs.Adaptive.Input.InputDialog.d__50.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at Microsoft.Bot.Builder.Dialogs.DialogContext.<BeginDialogAsync>d__32.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult()
at Microsoft.Bot.Builder.Dialogs.Adaptive.Actions.ActionScope.d__17.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at Microsoft.Bot.Builder.Dialogs.Adaptive.Actions.ActionScope.<BeginDialogAsync>d__6.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult()
at Microsoft.Bot.Builder.Dialogs.DialogContext.d__32.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at Microsoft.Bot.Builder.Dialogs.Adaptive.AdaptiveDialog.d__56.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Dialogs.Adaptive.AdaptiveDialog.d__45.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at Microsoft.Bot.Builder.Dialogs.DialogContext.<BeginDialogAsync>d__32.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult()
at Microsoft.Bot.Builder.Dialogs.DialogManager.d__37.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at Microsoft.Bot.Builder.Dialogs.DialogManager.d__30.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Bot.Builder.Dialogs.DialogManager.d__30.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Microsoft.BotFramework.Composer.Core.ComposerBot.d__10.MoveNext() in C:\bot-composer-sample\EchoBot-1\runtime\core\ComposerBot.cs:line 55

Bot Services bug customer-replied-to customer-reported needs-triage

All 8 comments

Thank you for providing a stack trace. What is the exception?

Please also provide the custom input dialog and schema you've used.

@EricDahlvang Thanks for reply

Exception : Object reference not set to an instance of an object.

class information

public class CustomInput : InputDialog
{
[JsonProperty("$Kind")]
public const string Kind = "CustomInput";

    [JsonProperty("customText")]
    public StringExpression Text { get; set; }

    [JsonProperty("outputFormat")]
    public StringExpression OutputFormat { get; set; }

    [JsonConstructor]
    public CustomInput([CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
    {
        this.RegisterSourceLocation(sourceFilePath, sourceLineNumber);
    }
    protected override Task<InputState> OnRecognizeInputAsync(DialogContext dc, CancellationToken cancellationToken)
    {
        var input = dc.State.GetValue<object>(VALUE_PROPERTY);
        if (!(input is string strInput))
        {
            return Task.FromResult(InputState.Invalid);
        }

        if (this.OutputFormat != null)
        {
            var (outputValue, error) = this.OutputFormat.TryGetValue(dc.State);
            if (error == null)
            {
                if (!string.IsNullOrWhiteSpace(outputValue))
                {
                    strInput = outputValue.ToString();
                }
            }
            else
            {
                throw new InvalidOperationException($"In TextInput, OutputFormat Expression evaluation resulted in an error. Expression: {OutputFormat.ToString()}. Error: {error}");
            }
        }

        dc.State.SetValue(VALUE_PROPERTY, strInput);
        return strInput.Length > 0 ? Task.FromResult(InputState.Valid) : Task.FromResult(InputState.Unrecognized);
    }
}

CustomInput.schema

{
"$schema": "https://schemas.botframework.com/schemas/component/v1.0/component.schema",
"$role": ["implements(Microsoft.IDialog)", "extends(Microsoft.InputDialog)"],
"title": "customText",
"description": "Sample custom input dialog",
"type": "object",
"additionalProperties": false,
"maxTurnCount": 3,
"properties": {
"customText": {
"$ref": "schema:#/definitions/stringExpression",
"title": "Text",
"description": "Value from callers memory"
},
"outputFormat": {
"$ref": "schema:#/definitions/stringExpression",
"title": "Output format",
"description": "Expression to format the output.",
"examples": [
"=toUpper(this.value)",
"${toUpper(this.value)}"
]
}
}
}

Is the CustomActionComponentRegistration included in the exported bot's startup.cs?

This is commented out by default in Composer's ejected runtime:

// This is for custom action component registration.
//ComponentRegistration.Add(new CustomActionComponentRegistration());

Also, is CustomActionComponentRegistration registering a CustomInput?

    public class CustomActionComponentRegistration : ComponentRegistration, IComponentDeclarativeTypes
    {
        public IEnumerable<DeclarativeType> GetDeclarativeTypes(ResourceExplorer resourceExplorer)
        {
            // Actions
            yield return new DeclarativeType<MultiplyDialog>(MultiplyDialog.Kind);
            yield return new DeclarativeType<CustomInput>(CustomInput.Kind);
        }

        public IEnumerable<JsonConverter> GetConverters(ResourceExplorer resourceExplorer, SourceContext sourceContext)
        {
            yield break;
        }
    }

@EricDahlvang Yes, I had did all the steps I can be able to add custom dialog in the composer this exception raising while running the application

Is the Initial Prompt defined in Composer?

image

image

@EricDahlvang Thank you its working fine.
Is possible we can define default initial prompt activity ?

@rvinothrajendran this can be accomplished by overriding OnRenderPromptAsync:

        protected override async Task<IActivity> OnRenderPromptAsync(DialogContext dc, InputState state, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (this.Prompt == null)
            {
                this.Prompt = new StaticActivityTemplate(MessageFactory.Text("missing initial prompt"));
            }

            return await base.OnRenderPromptAsync(dc, state, cancellationToken).ConfigureAwait(false);
        }

Added a PR to throw a more meaningful exception if the .Prompt is missing: https://github.com/microsoft/botbuilder-dotnet/pull/5065

Was this page helpful?
0 / 5 - 0 ratings