Late-binding in .NET

0.00 avg. rating (0% score) - 0 votes


Variable types are defined at compile time (e.g. string, integers):

String st = “hello world”;
Boolean ok = st.Contains(“hello”);

The compiler and linker will help verify that the argument types used to call a function matches the function’s signature.


At compile time, variable are declared as generic type (Object in .NET or Variant in VB6). The actual type will only be defined later at run-time, just before the object is used.

The developer needs to specify the function signatures and to ensure that the correct types are used.

In C/C++, late binding (a.k.a. run-time dynamic linking) often takes the form of LoadLibrary / GetProcAddress / FreeLibrary. The MSDN Library provides a good example of late binding in C/C++. Early biding is known as load-time dynamic linking in C++.

In VB6 and VB.NET, late-binding is possible with Option Strict turn off:

Option Strict Off
Dim st as Object = “hello world”
Dim ok as Object = st.Contains(“hello”)

‘st’ will be resolved to String type and ‘ok’ to Boolean at run-time.

Option Strict is by default off for all new VB.NET project created in VS2005. To change the default to On, go to the Visual Studio’s Tools | Options menu, click the Projects VB Defaults folder and set Option Strict to On.

However, in C#, late-binding needs to be performed via Reflection:

Object obj = new object();
obj = “Hello world”;
Type objType = obj.GetType();
Object objRet = objType.InvokeMember(“IndexOf”, BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, null, obj, new object[] { “world” });


  1. What is late binding?,
  2. Late Binding with Reflection,
0.00 avg. rating (0% score) - 0 votes


A tough developer who likes to work on just about anything, from software development to electronics, and share his knowledge with the rest of the world.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>