Sunday, March 16, 2008
« Web server issues, on top of issues | Main | Webcast on SOA, REST and related topics »

I have a question (helping a colleague do some research) for all .NET VB developers.

Do you use late binding in VB? If so, how/why do you use it? What are the scenarios where you find it of value?

I'll start this off with my own observations:

I use late binding when getting data of a given shape from unknown types.

For example, you can write a nice bit of reusable data access code that accepts data from a web service, LINQ object, etc. by using late binding. You can’t easily do this without late binding in fact, because the types of the objects are different even though their shapes are the same.

That dynamic interface concept that got dropped from VB9 would address this issue in a better way, but late binding makes it work too.

I also use late binding when creating some generic types. There are cases where generics and casting are problematic, but converting a value to type Object first allows you to do a cast or operation that wouldn’t otherwise be allowed. I don’t know if this is “late binding” as such, but it is a useful technique!

I have used late binding when dynamically loading an assembly for interaction. Ideally you’d require the assembly author to implement one of your interfaces, but that’s not always possible, and late binding is a particularly nice way to get “polymorphic” access to multiple assemblies that you don’t control.

What about you?


Monday, March 17, 2008 5:47:59 PM (Central Standard Time, UTC-06:00)
Late binding is particularly useful when working with COM objects, such as VSTO.
Monday, March 17, 2008 10:35:19 PM (Central Standard Time, UTC-06:00)
Option Explicit On
Option Strict On

' I never use late-binding, not even for Office Interop.
Tuesday, March 18, 2008 9:10:59 AM (Central Standard Time, UTC-06:00)
Sacrificing compile-time type-checking can cause major runtime problems, so if I do it then I am forced to do a lot of additional unit testing. Given that, there are not too many scenarios where it makes sense.

I have not actually used the VB late-binding feature, but I have used the reflection APIs to achieve the same effect. It seems to be useful when mapping data between different formats, e.g. DTO to Presentation. I generate the code that does it, because it is tiresome to write by hand.
Friday, March 21, 2008 12:15:25 PM (Central Standard Time, UTC-06:00)
I have add late binding to my new code generator I am writing. It allows for the code generator to send any object to the template engine interface.
Jeff Turner
Friday, April 04, 2008 2:13:57 PM (Central Standard Time, UTC-06:00)
I use it when I have to extend third party controls. Using the CSLA (1.x) framework I can make many controls easier to use by adding functionality that assumes I am passing BusinessBase and BusinessCollectionBase.
Paul
Tuesday, April 22, 2008 2:42:17 PM (Central Standard Time, UTC-06:00)
In communicating with COM components, VB.NET is better than C#
Please look at the example provided at
http://serviciipeweb.ro/iafblog/2007/12/22/Late+Binding+Outlook+VBNET+Versus+C.aspx

And after you do the examples in C# and VB.NET, when you decompile with Reflector, you will have the surprise that the generated codes are different...
Comments are closed.