Chapter 2. Visual Studio and Compiler Gotchas

.NET provides a very productive development environment, thanks to two main factors. One is the .NET Framework with its rich class library. The other is Visual Studio .NET, with its many wizards.

The code you write in C# or VB.NET is translated into MSIL by the C# compiler (csc.exe) or the VB.NET compiler (vbc.exe). A few idiosyncrasies of the compilers, and how Visual Studio presents them, can cause frustration in some cases and outright trouble in others. And several things get lost in the translation to MSIL. Not all source-code statements are translated quite as you might expect. This will come to light, for instance, when I discuss the odd behavior related to re-throwing an exception.

In this chapter I will focus on Visual Studio- and compiler-related gotchas.

GOTCHA #12 Compiler warnings may not be benign

A compiler aids developers by checking for syntax consistency, and tries to eliminate (or at least reduce) the possibility of errors. However, there are certain anomalies that the compiler takes less seriously than you might want it to. Reporting them as warnings instead of errors may lead to code that compiles but does not behave the way you expect. I urge you to treat warnings as errors to make sure they don’t escape your notice.

I have been preaching this since I started working with .NET. There were times when I wondered how much I should emphasize it, but I was reminded recently when a client asked me to help integrate a new ...

Get .NET Gotchas now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.