Invalid token 'while' in class, struct, or interface member declaration in very simple code

340

Solution 1

Based on the error, it sounds like the compiler thinks this code is typed directly in the body of a class/struct/interface declaration. Statements while/if/for/etc ... must appear with in a method.

Try moving this code into a method to fix the problem. If it's in a method, you likely have a mismatched brace problem.

Solution 2

There's nothing wrong with the while, it's something above it that's the problem. Check for mismatched braces and semicolons in a comment or something like that.

Solution 3

C# is not allowed to write code directly into the classes; it is allowed to write only data members and function members directly into the classes.

Share:
340
Arjun Raja
Author by

Arjun Raja

Updated on July 09, 2022

Comments

  • Arjun Raja
    Arjun Raja almost 2 years

    The bot that has been developed runs in the emulator locally without any problem.

    But when we hosted it in Azure. We're not getting any reply from bot.

    I tried testing the Bot Connection in dev.botframework.com, I get an "Endpoint authorization succeeded message".

    can anyone let me know what could be the issue.?

    • Admin
      Admin over 7 years
      What's the channel that you're using? Telegram, fb, skype?
    • Arjun Raja
      Arjun Raja over 7 years
      Skype and Webchat
    • Arjun Raja
      Arjun Raja over 7 years
      There is a good chance that I did something wrong with the connection string. <add name="DBCS" connectionString="Data Source=xxx.database.windows.net,1433;Initial Catalog=<dbname>;Integrated Security=False; TrustServerCertificate=False;User ID=yyy@xxx;Password=####;Connection Timeout=30" />
    • andrea-lam-MSFT
      andrea-lam-MSFT over 7 years
      Did you include System.Data.SqlClient as a provider?
    • Arjun Raja
      Arjun Raja over 7 years
      I tried including that also. It didn't work.
  • Arjun Raja
    Arjun Raja over 7 years
    Thanks for your reply.. My endpoint is already like what you have mentioned. From dev.bot framework I get a success message "Endpoint Authorization Succeeded." But, Whenever I send a message. It gets added as internal server error in issues of the channel.
  • Jim Lewallen
    Jim Lewallen over 7 years
    Are you able to debug your bot online to catch exceptions? It's possible Bot Framework is sending you an ActivityType other than "message" and your bot isn't handling it. For example, you may be getting "conversationUpdated" Activity with a null message body.
  • Arjun Raja
    Arjun Raja over 7 years
    The issue is fixed now. The bot.connector I used had a bug and it was fixed in 3.0.1. So I updated them.