Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8797773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:55:24+00:00 2026-06-13T23:55:24+00:00

Brief: How can I create two references in a .NET project to two ummanaged

  • 0

Brief:

How can I create two references in a .NET project to two ummanaged COM components that are identical except for their CLSID? They have the same ProgID, and the same Type Lib.

The Type Lib is what Visual Studio complains about when I attempt to create the second reference:

A reference to ‘XXX Type Library’ could not be added. A reference to this type library already exists. You must remove the reference ‘XXX’
before adding this one.

Thanks in advance.


Detailed:

I am creating a WPF application that provides integration with another application. The other application is a bit unusual in that its versions install as separate applications. Users can have multiple versions of the application running side by side on their computer.

My single WPF application is supposed to allow users to select the version of this other application they would like to work with. The other application has an unmanaged COM DLL for each version installed that I use to create the integration between my WPF app and this other application.

My WPF application has been working fine with the first version of the other application using a reference to the unmanaged COM component of version 1. The trouble starts when I try to reference the COM component of the second version.

I get the following error when I use “Add Reference” on the WPF project:
A reference to ‘XXX Type Library’ could not be added. A reference to this type library already exists. You must remove the reference ‘XXX’ before adding this one.

An examination of the registry indicates that the only differences in the registry information for the two versions of the COM component are the CLSD and the path to the actual DLL. The ProgID and the TypeLib values are the same across both components.

As the versions of the other application are really treated as separate applications I would prefer the COM components to be installed as different applications and I’m working with company on the next release.

For now I’m stuck trying to get version 2 integrated into my WPF application. I’ve seen many posts about extern alias and how to manually edit the project file to introduce aliases, but they all seem to start with managed assemblies and not unmanaged COM components. The contents of the project file are different for referenced unmanaged COM components and as I can’t create the second reference, adding an aliases tag to the references in the project files doesn’t help me.

I’ve seen people talking about using System.Addin and reflection but I wanted to confirm there isn’t a more straightforward approach before investigating more complex approaches.

Thanks for reading this far!


Following CasperOne’s advise I did the following:

  1. Ran the following using Visual Studio Command Prompt: tlbimp “c:\xxx1.dll” /out:”c:\NETxxx1.dll”
  2. Ran the following using Visual Studio Command Prompt: tlbimp “c:\xxx2.dll” /out:”c:\NETxxx2.dll”
  3. Added both newly created DLLs (Interop’s I guess) as references to my test project. I used the ‘Browse” tab to find them.
  4. I added code that pretty much followed casperOne’s code sample.

I had a bit of a panic about what name to use for my COM interface. In the case of the COM object I’m using, there is one main interface object, and all other objects that I use from that COM object are instantiated from within that main interface object (I.E. I make calls like: Foo x = y.GetNewFoo();).

using X1 = NETXXX1; using X2 = NETXXX2; Guid clsid1 = new Guid("xxx..."); Type type1 = Type.GetTypeFromCLSID(clsid1); X1.IApplication a1 = (X1.IApplication)Activator.CreateInstance(type1); X1.FooList f1 =a1.GetFooList(); Guid clsid2 = new Guid("yyy..."); Type type2 = Type.GetTypeFromCLSID(clsid2); X2.IApplication a2 = (X2.IApplication)Activator.CreateInstance(type2); X2.FooList f2 = a2.GetFooList(); foreach(X1.Foo f in f1) Console.WriteLine(f.Name); Console.WriteLine("*****"); foreach(X2.Foo f in f2) Console.WriteLine(f.Name);

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:55:25+00:00Added an answer on June 13, 2026 at 11:55 pm

    In this scenario, I would recommend against adding the reference through the “Add References” dialog in Visual Studio.

    Instead, use the Type Library importer to generate the reference from the command line, and then set a reference to that in your project normally (it will be a .NET assembly).

    Once you’ve done that, you’ll have two sets of types, the set of interfaces that the two classes implement, as well as one of the class definitions of the implementation of those interfaces.

    Instead of using the constructor to create this class, you would use the GetTypeFromCLSID method on the Type class to get the .NET Type for the COM object.

    Then, you would use that Type in a call to Activator.CreateInstance (since all COM objects have default constructors, this will work) and cast the result to the interface definition, like so:

    // The CLSID of the implementation you want to use.
    Guid clsid = ...;
    
    // Get the type.
    Type type = Type.GetTypeFromCLSID(clsid);
    
    // Create and cast to your interface.
    var i = (IMyComInterface) Activator.CreateInstance(type);
    

    When Activator.CreateInstance comes across a type that is a COM object, it creates a System.__ComObject (the root of all COM interop instances) which the CLR has support for (like calling IUnkown::QueryInterface when casting, like in the above code).

    Also, if you are up for it, you could define the interfaces in your code, and then cast to those, you don’t necessarily need the Type Library importer to generate them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create binary tree that contains two int values and one string
I have a perplexing issue that I can't seem to comprehend... I have two
I'm working on an events page where users can create events and their followers
I'm trying to create a rails app that fetches album scores from PitchforkMedia.com For
Brief introduction: I have this ASP.NET Webforms site with the particularity that it doesn't
I'm working on a simple rails project where I can create a post. My
I'll keep this brief: can anyone tell me why this doesn't work? The else
A small portion of my app contains a view were people can take brief
Brief question What command can I use to make my DataSet refresh it's connection
how can i use a particular UIActionSheet's button with some actioning (explain in brief)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.