Hi,
I performed some more investigation and hit the following. I now tried
to use the following call (in C#) to get a reference to the COM type:
object member =
Microsoft.VisualBasic.Interaction.CreateObject( "Users.Member", "" );
This would return me not a COM object, but instead a reference to
the .NET object which was originally exposed as COM. Still, I cannot
handle it as a COM type. When I call GetType() on the instance of the
object, I get:
[System.RuntimeType]: {Name = "Member" FullName = "Users.Member"}
base {System.Reflection.MemberInfo}: {Name = "Member" FullName =
"Users.Member"}
Assembly: {Users, Version=0.0.0.0, Culture=neutral,
PublicKeyToken=aakd895346d5aa6c}
AssemblyQualifiedName: "Users.Member, User, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=aakd895346d5aa6c"
The documentation of the CreateObject() method at
http://msdn2.microsoft.com/en-us/lib...eobject.asp x
reads:
"Creates and returns a reference to a COM object. CreateObject cannot
be used to create instances of classes in Visual Basic unless those
classes are explicitly exposed as COM components."
Strictly spoken, I do not get a reference to a COM object but to
a .NET object. There is nothing COM to it anymore.
If I would replace Users.Member with a PROGID of a COM type that I
know is unmanaged code, I would see that it is exposed as a COM
object. Performing a GetType() on this object, I get:
[System.RuntimeType]: {Name = "__ComObject" FullName =
"System.__ComObject"}
base {System.Reflection.MemberInfo}: {Name = "__ComObject"
FullName = "System.__ComObject"}
Assembly: {mscorlib, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b44a5d511234d013}
AssemblyQualifiedName: "System.__ComObject, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b44a5d511234d013"
I hope anyone can give me a clarification on this.
Thanks,
Tim
On 14 Dec, 11:46, tim.vanhek... (AT) googlemail (DOT) com wrote:
Quote:
Hi,
I am trying to create a unit test in .NET that tests the COM API of
a .NET assembly that was registered for COM interop (regasm). So the
call sequence is like: .NET -> PIA -> .NET. What seems to happen is
that a RCW is created that tells the CLR that the underlying type of
the PIA is a .NET type (Users.Member). This then cannot be cast to the
type Company.Intranet.Interop.Users.MemberClass from the PIA.
System.InvalidCastException : Unable to cast object of type
'Users.Member' to type 'Company.Intranet.Interop.Users.MemberClass'.
My main question is, what does the CLR do when COM (!) interopping to
a COM exposed .NET assembly? How can I achieve that it is actually
using the COM types instead of the .NET type.
Greetz,
Tim |