grefly
grefly

Reputation: 1199

If "Option Strict" is off, why does compilation fail with "Option Strict On"?

I have inherited a VB.NET application that I need to compile so I can run dokumentation on it. I first received "Option Strict On disallows implicit conversion from x to y" errors, so I turned off the Option Strict option in the Project file.

So why do I still fail with the same error message?

Upvotes: 0

Views: 1884

Answers (2)

Konrad Rudolph
Konrad Rudolph

Reputation: 546093

I first received "Option Strict On disallows implicit conversion from x to y" errors, so I turned off the Option Strict option in the Project file.

As opposed to, say, fixing the error? Pardon my sarcasm but you have chosen the wrong fix: instead of disabling Option Strict you should fix the error that the compiler indicated. After all, the whole point of Option Strict is to help make the code more robust.

That said, there are four places which control Option Strict (and all other options):

  1. The Visual Studio options which control project defaults,
  2. The project settings,
  3. The web.config compiler command line,
  4. On file basis, the top lines of a source code file.

Check that Option Strict is off in places 2., 3. and 4. and that it is on in place 1 (because turning Option Strict Off in general is a really, really bad idea). The problem should be gone then.

Also try disabling the setting explicitly in the web.config. I’m going on a limb here but according to forums.asp.net this can be done by adding the following directly inside the <configuration> node:

<system.codedom>
    <compilers>
        <compiler compilerOptions ="/optionstrict-" language="vb;vbs;visualbasic;vbscript"
                  extension=".vb"
                  type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    </compilers>
</system.codedom> 

… probably there already exists a <compiler> node – modify that.

Upvotes: 7

Akram Shahda
Akram Shahda

Reputation: 14781

Option Strict is prevents program from automatic variable conversions, that is implicit data type conversions.

Upvotes: 0

Related Questions