Option Strict [On|Off|SortOf]

Option Strict [On|Off|SortOf]

  • Comments 4

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."

Leave a Comment
  • Please add 1 and 1 and type the answer here:
  • Post
  • On the same theme - customizable compiler options for treatment of error status - I have been looking for a way to override the compiler abort after 100 errors have been reported.  I realize that there is a problem in many cases with an initial error causing a storm of secondary errors to no good end, but in this case I would like to assess the amount of errors generated when trying to compile an output from the VB6 to VB.NET conversion "wizard" before starting to integrate it into already converted source. Unfortunately the compiler gives up before completing this task, which hinders my being able to quantify the number of compilation errors needing attention.

  • まあまあ厳しくして欲しい (1/3) ~Option Strict SortOfって?~

  • まあまあ厳しくして欲しい (2/3) ~Option Strict に関連する3つの条件~

  • まあまあ厳しくして欲しい (1/3) ~Option Strict SortOfって?~

Page 1 of 1 (4 items)