0

I have a rather large VB ASP.NET WebForms page, and when I edit it, Visual Studio automatically formats it for me. Now when I run it I get the error:

BC30205: End of statement expected

at some arbitrary line of code such as

myCommand.CommandText = sqlStr

This error only occurs at runtime; Visual Studio does not report it at compile time. I don't see anything wrong with the line of code in question or anything around it (slightly redacted; the first line is a continuation of a previous statement):

XXXXDBTools.DBFunctions.CheckDateSql(Request.Form("XXXXBillingEndDate")) & ") "
myCommand.CommandText = sqlStr
rows = myCommand.ExecuteNonQuery()

Why would an erroneous compiler error occur only at runtime, and how can I fix it so I can make changes to the page without it crashing on me?

Trevor
  • 7,777
  • 6
  • 31
  • 50
ekolis
  • 6,270
  • 12
  • 50
  • 101
  • Can you post the full stack trace please? Also try and remove `& ") "` from the first line which is more than likely your culprit as there's an additional programming element follows at the end. – Trevor Sep 05 '19 at 19:41
  • `.CheckDateSql(Request.Form("XXXXBillingEndDate")) & ") "` is not a valid statement. It is a concatenation of a function result and a string that is not assigned to anything, this is not allowed. – GSerg Sep 05 '19 at 19:44
  • `Why would an erroneous compiler error occur only at runtime` is because it's a runtime error, not a compile error. – Trevor Sep 05 '19 at 19:48
  • @Çöđěxěŕ [BC30205](https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/error-messages/end-of-statement-expected) is a compile time error. It happens "at runtime" because the portion of the source code that contains it is [compiled later](https://softwareengineering.stackexchange.com/a/84523/30872). – GSerg Sep 05 '19 at 19:52
  • @Çöđěxěŕ No, the statement is a compile time error. Try putting `SomeFunction("asd") & " )"` onto a separate line in a sub in a console VB.NET app, it will not compile. On contrary, `Dim result = SomeFunction("asd") & " )"` is perfectly fine. – GSerg Sep 05 '19 at 19:54
  • `This error only occurs at runtime; Visual Studio does not report it at compile time` so are you saying the OP isn't experiencing this then? Of course it comes down to *compile* time when running; it comes later, but still only occurs during runtime, not building the solution. – Trevor Sep 05 '19 at 19:56
  • @Çöđěxěŕ The OP may have the squiggly lines disabled, or the code can be in a place where the syntax highlighter gets too confused to correctly highlight it. When the actual compiler gets around to compile the aspx page, it raises the compile time error (which is after the rest of the app is already running). If the OP is not using [precompilation](https://softwareengineering.stackexchange.com/a/84523/30872), which they apparently do not, then it will not occur while building the solution. – GSerg Sep 05 '19 at 19:58
  • @GSerg thanks for the links, I didn't know that `the lack of precompilation means that you may not catch an error in the mark-up until a specific component of the web app is called.`; learned something new about this. But, it still can be a runtime error right, if a specific component is called according to that statement? If it's not called, then the error wouldn't exist? I bet this isn't the same when inline code is introduced. – Trevor Sep 05 '19 at 20:02
  • @GSerg have a look [here](https://stackoverflow.com/a/21134799/1797425) it actually can depend on how the pages are deployed, so I would assume in all honesty this *could* be an edge case at times. – Trevor Sep 05 '19 at 20:10
  • The previous line I shared with the `DBFunctions` call is the last line of a long string concatenation; I just left out the other lines because there were a lot of them. Is the _ character required for line continuation when it would be immediately following a & or + for string concatenation, or is it optional? I've seen a lot of line continuations without the _, and Visual Studio wants to insert it for me at times, but that seems to be breaking something here... – ekolis Sep 06 '19 at 15:16
  • 1
    @ekolis The complete list of places where implicit line continuation is allowed is [here](https://learn.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/statements#implicit-line-continuation). – GSerg Sep 06 '19 at 17:36

0 Answers0