What is Option Strict in VB.NET?
Quick Answer
Option Strict On makes the VB.NET compiler reject implicit narrowing conversions and late binding — you must write explicit casts (CInt, CType, DirectCast), and every call is resolved at compile time. It should be on in every project; leaving it off hides type errors until run time.
Option Strict On tells the compiler to stop being lenient. It disallows implicit narrowing conversions — so you can't silently assign a Double to an Integer — and it disallows late binding, so calling a method on an Object has to resolve at compile time. The effect is that a whole class of errors that would otherwise be a run-time InvalidCastException becomes a compile error instead. It should be on everywhere. A typical job on an old VB.NET codebase is turning it on and working through everything it flags, which usually surfaces genuine bugs.
Three related options:
Option Explicit On(default) — every variable must be declared.Option Strict On— no implicit narrowing (Object→String,Double→Integer), no late binding onObject, no implicitObjectconversions in operators. Turns run-timeInvalidCastExceptions into compile errors.Option Infer On— allowsDim x = 5local type inference (still statically typed).
With Option Strict Off, Dim total = value1 + value2 where the values are Object compiles and does late-bound arithmetic that can blow up at run time. Turning it on across a legacy codebase is a common hardening task — you fix the flagged conversions and often find real bugs.