September 25th, 2007

Option Strict [On|Off|SortOf]

Yesterday I got a question from a developer asking whether or not we could add something called “Option Strict Warn” to the language.  This would give a developer a warning when using something like late binding or an implicit conversion, rather than disabling it altogether (through an error).

As it turns out the ability to set custom custom values for Option Strict is actually already in Visual Studio.  To test this out double click on “My Project” and click on the Compile tab of the Application Designer.

The top 3 lines of the grid (under “Warning configurations”) contain the following options:

– Implicit Conversion

– Late binding; call could fail at runtime

– Implicit type; object assumed

When you change Option Strict to On you’ll see that all 3 of these change to “Error.”  When you change it to Off they all change to “None.”  If you change the dropdown to “Warning” you’ll see the Option Strict box updates to “(custom)”.

If you open up a .vbproj file you can see how this information gets passed through the project system to the compiler.  There’s a <NoWarn> element that takes a comma-separated list of warnings to disable, which gets passed to the compiler (through the /nowarn:<number_list> switch).

While we don’t recommend manually editing the .vbproj file, you can actually use this mechanism to disable other warnings which aren’t displayed in the grid.  Anything inside the <NoWarn> or <WarningsAsErrors> elements will get passed to the compiler.

If you want to find out a warning’s ID just right-click it in the Error List and click “Show Error Help.”

Author

0 comments