What is the difference between a "syntax error" and a "compiler error" as Visual Studio sees it? Or, put another way, why are some "compile-time" errors underlined with red wavy lines and some with blue wavy lines? Here is an example:
The red underlined error above has this description:
No overload for method 'ValidateFilteredRecipient' takes 6 arguments
The blue underlined error has this description:
'ValidateBuild': cannot declare instance members in a static class
It's not clear to me what the distinguishing characteristics of the two errors are.
I thought finding the answer would be a piece of cake: I'd just google it and the first result would be an MSDN page expounding this topic fully; however, very surprisingly, this was not the case. I started off by trying to google the colors (since I didn't yet know red meant "syntax error" and blue meant "compiler error"):
visual studio red underline vs. blue underline
No help there. Then I tried these searches:
visual studio error underline color meanings
visual studio underline color meanings
I could see that this was going nowhere, so I googled a bit more and figured out where the colors were set in VS: Tools > Options > Environment > Fonts and Colors. By the way, the inability to search the huge list here is extremely annoying, but I figured out that "syntax errors" have the red wavy underline, and "compiler errors" have the blue wavy underline.
So what do those mean? Back to Google:
visual studio compiler error vs. syntax error
Nothing relevant. Here's the closest I've found, from MSDN:
Fonts and Colors, Environment, Options Dialog Box
This page has these entries:
Compiler Error -- Blue squiggles in the editor indicating a compiler error.
and
Syntax Error -- Parse errors.
Not at all helpful -- emphasis on "at all". I have always thought I knew what a "syntax error" was, at least, and Wikipedia agrees:
a syntax error is an error in the syntax of a sequence of characters or tokens that is intended to be written in a particular programming language.
Also, here is what what it has for syntax:
the syntax of a computer language is the set of rules that defines the combinations of symbols that are considered to be a correctly structured document or fragment in that language.
So, going back to my "syntax error" from above:
No overload for method 'ValidateFilteredRecipient' takes 6 arguments
How is that a syntax error per the definition I've included here? Actually, in my opinion, the "compiler error" I got more-closely meets this definition of a syntax error:
'ValidateBuild': cannot declare instance members in a static class
Can someone please help me figure this out?
Both Syntax and compiler errors will prevent your code from compiling.
Syntax Errors refer to how your code interacts with other pieces of code. Things like type mismatches when passing parameters to functions etc.
Compiler errors on the other hand refer to more fundamental architectural violations like trying to inherit from sealed classes or defining non static members inside static classes. These go against the definition of the language rather than the usage of the language.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With