How to get a Primary Interop Assembly for a Microsoft COM component?

  • Thread starter Thread starter Chango V.
  • Start date Start date
C

Chango V.

Hello,

We seem to need a PIA for MSXML 4. According to the documentation, only the
original publisher of a COM type library is supposed to create a .NET PIA.
As far as I know, Microsoft hasn't done that yet. Our problem is that we
very much want to create a PIA for a COM component of ours, but TlbImp.exe
/primary insists that all referenced dependencies be PIAs as well. Our
component has a type library reference to MSXML 4, hence the problem... I
presume many people run into similar problems with various MS COM
components. As a last resort, we'll make a PIA for MSXML 4. But PIAs are
supposed to be deployed in the GAC, which creates potential for conflicts
with unrelated application... Any help will be appreciated.

// Chango

NOTE: This post is from an anti-spam, non-existent email address. For
further communication, please reply to the Newsgroup and/or contact me
directly at (e-mail address removed).
 
Hi Chango,

Thank you for posting. Regarding on the issue, I am
finding proper resource to assist you and we will update as soon as posible.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security(This posting is provided "AS IS",
with no warranties, and confers no rights.)
 
Hi Chang

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to create a PIA for MSXML4
COM. If there is any misunderstanding, please feel free to let me know.

Based on the following KB article, we can see that a COM type library that
is imported as an assembly and that is signed by someone other than the
original type library publisher cannot be a PIA. Only the type library
publisher can create a PIA that becomes the unit of official type
definitions for interoperating with the underlying COM types.

http://support.microsoft.com/?id=304295

So if you need to interop with the MSXML library, I think you can just
create a strong-named wrapper for it instead of making a PIA. Could you
please omit the /primary option and try the following statement?

TLBIMP C:\WINDOWS\system32\msxml4.dll /out:MyWrappers.dll /keyfile:mykey.snk

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Hello Kevin,

Thanks for the response. Yes, so far we used a strong-named import of the
MSXML type library, but now the problem is that we have a very compelling
reason to make a PIA for our own COM component, which references MSXML. As I
explained before, TlbImp requires all dependencies of a PIA to be PIAs too.

How do people deal with this problem in general? There are tens of popular
Microsoft COM APIs now used from .NET. The default importing of these type
libraries works just fine. So it would take Microsoft little effort just to
strong-name them and call them the "official PIAs"... Otherwise, we really
seem to be forced to break the PIA rules, or not be able to avail from them.

//
 
Hi Chango,

If your own COM component is referencing MSXML, you needn't create PIA for
MSXML. What you need to do is creating a PIA for your own COM. When the
users calls your PIA, the PIA calls your own COM component and the COM
references MSXML.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Well, this is the crux of the problem: We can't generate our PIA, because
TlbImp insists all dependencies be PIAs too. Here's the actual command and
output:
tlbimp.exe WorXConverter.dll /keyfile:mykey.snk /verbose /primary

Microsoft (R) .NET Framework Type Library to Assembly Converter 1.1.4322.573
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.

Resolving reference to type library 'MSXML2'.
TlbImp error: System.ApplicationException - Referenced type library 'MSXML2'
does not have a primary interop assembly registered.

If I first import MSXML4.dll [note the typelib name within is MSXML2] and
specify the reference explicitly on the TlbImp command line
(/reference:Interop.MSXML2.dll), the error message is consistent:

TlbImp error: System.ApplicationException - Referenced assembly
'Interop.MSXML2'
is not a primary interop assembly.

Can I possibly be missing something, or Microsoft should really publish PIAs
for popular COM type libraries in order to make the whole PIA idea work for
everyone else?

//
 
Hi Chango,

I would like to know how your COM component is referencing to MSXML. From
the message, it seems that it is referring to an interop assembly of MSXML.
If you're working on a pure COM component, there needn't be any interop
relations between your COM and MSXML. So there will not be the PIA issues.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
It's a typical case: The original COM component uses the MSXML 4 API. To do
this, the IDL file contains the statement importlib("msxml4.dll"). This
results in a type library reference embedded in our type library. When
TlbImp.exe imports our type library, it sees the embedded reference to the
MSXML type library and tries to resolve it. The default behavior is to just
automatically generate an interop assembly for any referenced type library
(MSXML in our case) and reference that assembly in the interop assembly
generated for the main COM type library being imported. But as I showed you
in the previous post, this doesn't work if the /primary switch is used.

The HARD RULE seems to be that every explicit dependency of a PIA must be a
PIA too. So, we are back to the originally stated problem: Is there any
possible way for Microsoft to provide a PIA for MSXML 4 (and other popular
components too, in general)? Or is there something fundamental about how
these things are supposed to be working that I am still missing? Please
help...

// Chango
 
Hi Chango,

In this case, no PIA for MSXML is needed. Let me explain this to you.
First, PIA is used for interop. It makes a managed assembly to call a COM
component. However, in this case, MSXML is called by a COM component
written by you. So there is no interop here. It's just one COM referencing
another COM.

So what we need to do is to build a PIA for your COM component. Since no
PIA is used for MSXML, you can build the PIA for your own COM successfully.

Furthermore, currently we don't have any PIAs for MSXML and I don't think
we will release such PIAs in the future.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top