Tags: | Posted by Admin on 5/17/2008 4:08 AM | Comments (0)

    [UPDATE]
    Solved... well, not solved, but explained.  The VB team has valid reasons for not supporting object as an extension parameter type.  The key to take away from the linked article is that, when you specify object, it means "take anything *other* than an object".

    http://blogs.msdn.com/vbteam/archive/2007/01/24/extension-methods-and-late-binding-extension-methods-part-4.aspx
    [/UPDATE]

    I'm trying to create an extension method that takes any object. It's irrelevant what I want it to do. The problem is that I can't get Extension Methods that take objects to work correctly in VB.NET. I don't have any problems with doing this in C#.

    I created a simple console app to show my issues. I have two extension methods. One takes an object, and one takes a string. The code, along with the issues I'm having, are shown in detail below.

    With a string, both methods show up in Intellisense.

    clip_image001

    With an object, the object extension method doesn't appear

    clip_image002

    However, it will compile

    clip_image003

    When running, however, an error occurs on the o.TestObjExt() line

    clip_image004

    Oh, but wait, if I run the same line from the Immediate window, it works!

    clip_image005

    So, I don't know what's happening. It seems to be a compiler issue, but I can't figure it out. Does anybody have any ideas what might be going on?