0

I've a chatbot using Bot framework and I want to connect it to WhatsApp channel using the Infobip adapter and I'm getting 2 errors:

  1. A local or parameter named 'turnContext' cannot be declared in this scope because that name

2.A local or parameter named 'exception' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter

    public class InfobipWhatsAppAdapterWithErrorHandler: InfobipWhatsAppAdapter
    {
    public InfobipWhatsAppAdapterWithErrorHandler(InfobipWhatsAppAdapterOptions 
    infobipWhatsAppOptions, IInfobipWhatsAppClient infobipWhatsAppClient, 
    ILogger<InfobipWhatsAppAdapterWithErrorHandler> logger)
        : base(infobipWhatsAppOptions, infobipWhatsAppClient, logger)
    {
        OnTurnError = async (turnContext, exception) =>
        {
            OnTurnError = async (turnContext, exception) =>         
            {
                // Log any leaked exception from the application.
                logger.LogError($"Exception caught : {exception.Message}");

                // Send a catch-all apology to the user.
                await turnContext.SendActivityAsync("Sorry, it looks like something went wrong.");
            };
        };
    }
}

the error is on this line: OnTurnError = async (turnContext, exception) =>

1 Answers1

0

Unfamiliar with the framework, but looks like you're accidentally trying to declare the function twice, and inside itself?

Try just assigning once:

OnTurnError = async (turnContext, exception) =>
{
    // Log any leaked exception from the application.
    logger.LogError($"Exception caught : {exception.Message}");

    // Send a catch-all apology to the user.
    await turnContext.SendActivityAsync("Sorry, it looks like something went wrong.");
};

You're defining two functions here (one inside the other) and they're both taking in parameters with the same name. That's what the error is telling you; it can't differentiate the parameters since you're reusing the names.