in

Platinum Bay

Peace, Love and Visual Studio Team System

.NETicated

Swing and a Miss, Minus the Swing

So the contest I was running is over, with a startling ZERO entries. I guess no one wanted $25 to ThinkGeek.com.

The answer? Take a look at these two lines of code:

Dim typeName As String = Microsoft.VisualBasic.Information.TypeName(objectProvider.GetObject)
Dim t As Type = Type.GetType(typeName, True, True)

Got it yet? Ok, let's review.

The TypeName method returns the underlying type name for an object, which in this case is a System.__ComObject. The underlying object that System.__ComObject is representing could be any serializable object.

The next line then attempts to cast the object given the type name. The problem? Microsoft.VisualBasic.Information.TypeName does not return a fully qualified name, and the custom type may not be found.

More info - http://msdn2.microsoft.com/en-us/library/microsoft.visualbasic.information.typename(vs.80).aspx

Comments

December 20, 2007 3:12 PM

Yeah, I was late getting to the contest but I think that I hit a home run ;-) with my answer.

Regarding the Type information, you'll need to do some research on IDispatch & ITypeInfo.  If the underlying COM object supports IDispatch, you can get everything you need from there.

 

Leave a Comment

(required )  
(optional )
(required )  
Add

About Steve

Steve Andrews has been working as a developer for more than 8 years. During this time, he has designed and developed applications in such widely varying areas as trust accounting, medical information management, supply chain management, and retail systems. He has firsthand developer experience with a variety of languages, including Java, VB, and .NET. Most recently, he has been immersed in SharePoint. He is currently employed at RDA Corporation in Philadelphia, PA, as a Software Engineer and a team member in the Architectural Guidance evangelism team. Steve is also an MTCS (x2), ICSOO, and .NET fanatic.
Powered by Community Server (Commercial Edition), by Telligent Systems
© Platinum Bay | Some Rights Reserved Creative Commons License

Disclaimer: The information in this weblog is provided "AS IS" with no warranties, and confers no rights. This weblog does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion. Feel free to challenge me, disagree with me, or tell me I'm completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or annonymous comments) - so keep it polite, please.