Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / December 2007

Tip: Looking for answers? Try searching our database.

Testing the COM API of a .NET interop assembly

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tim.vanhekken@googlemail.com - 14 Dec 2007 10:46 GMT
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
tim.vanhekken@googlemail.com - 14 Dec 2007 12:58 GMT
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/library/microsoft.visualbasic.interaction.creat
eobject.aspx

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...@googlemail.com wrote:
> Hi,
>
[quoted text clipped - 15 lines]
>
> Tim
wpcmame - 19 Dec 2007 11:07 GMT
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).

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.