What is late binding in VB.NET, and why is Option Strict important?
Quick Answer
Late binding is calling a member on an Object variable where the method is resolved at run time via reflection, not at compile time. With Option Strict Off, VB.NET allows it silently; with Option Strict On, you must cast to the real type first. Late binding is slower and pushes “method not found” errors to run time.
Late binding is when you have an Object variable and you call a method on it, and VB.NET figures out at run time — using reflection — whether that method exists and calls it. Option Strict Off lets you do this without any warning, which means a typo in a method name isn't caught until that line executes, and it's slower. Option Strict On forces you to cast to the actual type so the call is resolved at compile time. The legitimate use for late binding is Office or COM interop. C#'s dynamic keyword is the explicit equivalent.
Dim x As Object = GetThing() : x.DoStuff()— with Strict Off this compiles and reflects at run time; with Strict On it's an error.- The one place late binding is legitimately useful is COM/Office interop where the type library isn't referenced.
- C# gets the same behaviour explicitly with the
dynamickeyword.