I have a COM DLL that has a property of type Object. In .NET, I try and set the property to an instance of a COM Visible .NET class, but keep getting an invalid cast exception. I have tried several different methods of passing the class, but can't get it to work. For example, I have tried the following:
Example 1
Example 2VB Code:
Dim _myObject as Object = New clsTest _comObject.ObjectProp = _myObject
Example 3VB Code:
Dim _myObject as New clsTest _comObject.ObjectProp = _myObject
VB Code:
Dim _myObject as New clsTest _comObject.ObjectProp = CType(_myObject, Object) _comObject.ObjectProp = DirectCast(_myObject, Object)
None of those work, but if I set _myObject = New TextBox, for example, it DOES work. The COM property's Let routine accepts the Object parameter ByRef.
Any ideas?




Reply With Quote