HighTechTalks DotNet Forums  

Testing the COM API of a .NET interop assembly

Dotnet Framework (Interop) microsoft.public.dotnet.framework.interop


Discuss Testing the COM API of a .NET interop assembly in the Dotnet Framework (Interop) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
tim.vanhekken@googlemail.com
 
Posts: n/a

Default Testing the COM API of a .NET interop assembly - 12-14-2007 , 05:46 AM






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

Reply With Quote
  #2  
Old   
tim.vanhekken@googlemail.com
 
Posts: n/a

Default Re: Testing the COM API of a .NET interop assembly - 12-14-2007 , 07:58 AM






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


Reply With Quote
  #3  
Old   
wpcmame
 
Posts: n/a

Default RE: Testing the COM API of a .NET interop assembly - 12-19-2007 , 06:07 AM



How did you define the COM interface.

..Net doesn't support the classinteface. (AutoDual) You need to either use a
dispatch-only (AutoDispatch) or an explicit interface (None).


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.