Click here to Skip to main content
13,343,419 members (54,479 online)
Click here to Skip to main content
Add your own
alternative version


32 bookmarked
Posted 6 Oct 2004

Referencing binary incompatible versions of COM components in Visual Studio .NET

, 6 Oct 2004
Rate this:
Please Sign up or sign in to vote.
This tutorial explains how to configure Visual Studio .NET projects when working with COM components whose binary compatibility is broken but the library name and method signatures are retained.


When vendors release different versions of COM components, they retain the binary compatibility to make sure that programs which are compiled with one version of the component work with another version (at least backward compatible). Examples are ADODB, MSXML etc. But sometimes, an odd chicken is hatched and this binary compatibility is broken. This situation creates problems in development, and different versions of project files have to be created. Any references in a Visual Studio project for the libraries built around that COM component have to be changed when working with different versions. This article discusses a strategy to facilitate development using different versions of the same COM component whose binary compatibility is broken.

Referencing COM components in Visual Studio .NET project

Right click on References in project tree, and in Add Reference dialog, select COM tab. Select the COM component from the displayed list or Browse for the library file. Visual studio uses the tlbimp tool to generate an Interop wrapper over the component. This wrapper assembly is named Interop.library.dll by the project. This assembly is identified by the type library GUID and is shown as Identity in Assembly Properties as shown here:

When binary compatibility is broken with different versions of the COM component, the library GUID changes and the Interop assemblies are no longer compatible. But in our case, the library name in the type library has not changed. That means the namespace library does not change. To simulate this situation, I have created a simple COM component using Visual Basic 6.0. This code contains a library called TestDll with a component called TestComp. This component has one method DisplayTestMessage() which will display a message giving the version number.

Below are the Visual Basic project settings which broke the binary compatibility:

Using this code, I have created two versions of the COM component, and, and placed them in different directories. The differences, in the components generated, will be the GUIDs (Identity) and the message box. The library name, component name, and method signature are all same. Now, to use this component in a .NET project, the following code is used:

using System;
using System.Windows.Forms;
using TestDll;

namespace TestReference
    public class TestForm : System.Windows.Forms.Form
        static void Main() 
            TestDll.TestCompClass test = new TestDll.TestCompClass();

When we try to add reference to both the versions in a test application by selecting the DLLs in Add Reference dialog, after one DLL is added, for the second DLL, Visual studio gives the following error because the namespace is same:

To avoid this warning message, here is a solution:

  • First, select the version of the DLL in References and save the project.
  • Open the .csproj or .vbproj file in Notepad outside Visual Studio.
  • In the <Build><References> section, look for the library and change the name. In the present case, I have changed it from TestDll to TestDll_1.0.0.0.
        Name = "TestDll_1.0.0.0"
        Guid = "{CB8AD23D-7243-4DF6-A7D2-77E8B9AC4993}"
        VersionMajor = "1"
        VersionMinor = "0"
        Lcid = "0"
        WrapperTool = "tlbimp"
  • Save the file in Notepad and reload in Visual Studio. This should refresh your References displaying the new name (as shown below).
  • Now, add the Reference to the DLL file containing version of the library and save the project.
  • Open the project file in Notepad and repeat the steps above, and change the Reference name from TestDll to TestDll_2.0.0.0.

Important: Remember to save the project in Visual Studio to see the changes in .csproj or .vbproj file!

Now we have a project referencing both the versions, and interestingly, you can tell from the project visually which version of DLL your project is using and the program is compiled with, by looking at the small warning icon (see the image below). To simulate a real world situation (where only one version of component is installed), rename one of the COM component DLL files, and recompile the project. A warning icon appears in the Visual Studio but the program still works with whichever version is available.

The technique discussed above only makes development environment easier. But while deploying, we still have to make sure to build the correct version of the Interop assembly targeting the clients, and deploy it with the executable, mainly because the names of the assemblies will be same across different versions of COM components.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Sriram Chitturi
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralReport DLL made in VB6 for VBNet Pin
reyboy6-Oct-04 16:39
memberreyboy6-Oct-04 16:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180111.1 | Last Updated 6 Oct 2004
Article Copyright 2004 by Sriram Chitturi
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid