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
VB Code:
  1. Dim _myObject as Object = New clsTest
  2.  
  3. _comObject.ObjectProp = _myObject
Example 2
VB Code:
  1. Dim _myObject as New clsTest
  2.  
  3. _comObject.ObjectProp = _myObject
Example 3
VB Code:
  1. Dim _myObject as New clsTest
  2.  
  3. _comObject.ObjectProp = CType(_myObject, Object)
  4. _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?