web analytics
The type or namespace name 'MSXML2' could not be found Options
codeling
Posted: Monday, November 28, 2016 1:53:14 PM

Rank:Advanced Member
Groups: Member
Joined: 12/11/2015
Posts: 964
Points: 4059

Compiling a C# program and get the following compiler error:

Error 173 The type or namespace name 'MSXML2' could not be found (are you missing a using directive or an assembly reference?) 

 

 

Sponsor
Posted: Monday, November 28, 2016 1:53:14 PM
codeling
Posted: Monday, November 28, 2016 1:57:32 PM

Rank:Advanced Member
Groups: Member
Joined: 12/11/2015
Posts: 964
Points: 4059

To create interop assembly MSXML2.DLL, use tool tlbimp.exe:

tlbimp c:\windows\system32\msxml6.dll

It will create MSXML2.dll in the current directory. Why MSXML2 was created out of MSXML6? The reason is taht msxml6.dll contains a type library named MSXML2. So tlbimp created a managed assembly MSXML2, which become also the DLL name.

The Type Library Importer converts the type definitions found within a COM type library into equivalent definitions in a common language runtime assembly. The output of Tlbimp.exe is a binary file (an assembly) that contains runtime metadata for the types defined within the original type library. You can examine this file with tools such as Ildasm.exe.

This tool is automatically installed with Visual Studio. To run the tool, use the Developer Command Prompt.

codeling
Posted: Monday, November 28, 2016 2:06:36 PM

Rank:Advanced Member
Groups: Member
Joined: 12/11/2015
Posts: 964
Points: 4059

The PIA(Primay Interop Assembly) contains the official description of the types as defined by the COM publisher of those types. The PIA may contain certain customizations that make the types easier to use from managed code. The PIA is always signed by the publisher of the original COM type. If you publish a COM component, it is a good idea to provide a primary interop assembly, unless you don't want your component to be used from managed code.

Any interop assembly that is not provided by the publisher of the COM types is considered unofficial and should be avoided. Because the types defined in such an assembly are not to be signed by the publisher of the PIA, they are incompatible with the definitions provided in the PIA.

How do I make a PIA for my COM type library?

In most cases, creating a PIA is easy. The Tlbimp (Type Library Importer) tool provided in the Microsoft® .NET Framework SDK is capable of creating an interop assembly from an existing type library. The /primary switch on Tlbimp is used to create a PIA. All PIAs must be signed by their publisher so the publisher key must also be supplied with the /keyfile switch. For example:

TlbImp Widget.tlb /primary /keyfile:AcmeKey.snk /out:WidgetLib.dll

In the example above, Widget.tlb is the type library being imported, AcmeKey.snk is the keyfile containing the public key for the Acme Company, and WidgetLib.dll is the PIA that will be generated. A test keyfile can be generated with SN utility (SN.EXE —k AcmeKey.snk). Before the assembly is actually deployed, it should be signed with the company's real key. The same key should be used to sign all assemblies from a single company.

Users browsing this topic
Guest

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.


© 2018 Digcode.com. All rights reserved.